Skip to content

Commit accc214

Browse files
author
Javier López Peña
committed
Use numpy mask for inflows and outflows
1 parent e50c610 commit accc214

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

numpy_financial/_financial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,9 @@ def irr(values, guess=None, tol=1e-12, maxiter=100):
757757

758758
# If no value is passed for `guess`, then make a heuristic estimate
759759
if guess is None:
760-
inflow = sum(x for x in values if x > 0)
761-
outflow = -sum(x for x in values if x < 0)
760+
positive_cashflow = values > 0
761+
inflow = values.sum(where=positive_cashflow)
762+
outflow = -values.sum(where=~positive_cashflow)
762763
guess = inflow / outflow - 1
763764

764765
# We aim to solve eirr such that NPV is exactly zero. This can be framed as

0 commit comments

Comments
 (0)