Skip to content

Commit 53cef84

Browse files
committed
ENH: IRR: Select positive solution if available
1 parent 61376c5 commit 53cef84

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

numpy_financial/_financial.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,12 @@ def irr(values):
781781
# NPV(rate) = 0 can have more than one solution so we return
782782
# only the solution closest to zero.
783783
rate = 1/res - 1
784+
785+
# If there are any positive solutions prefer those over negative
786+
# rates.
787+
if (rate > 0).any():
788+
rate = np.where(rate > 0, rate, np.inf)
789+
784790
rate = rate.item(np.argmin(np.abs(rate)))
785791
return rate
786792

0 commit comments

Comments
 (0)