Skip to content

Commit 4c7b4a4

Browse files
committed
Update _financial.py for line too long error
- internal_rate_of_return -> eirr - abs_internal_rate_of_return -> abs_eirr
1 parent 16d4399 commit 4c7b4a4

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

numpy_financial/_financial.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -827,38 +827,38 @@ def irr(values, raise_exceptions=False):
827827
# as eirr = g - 1 (if we are close enough to a solution)
828828

829829
g = np.roots(values)
830-
internal_rate_of_return = np.real(g[np.isreal(g)]) - 1
830+
eirr = np.real(g[np.isreal(g)]) - 1
831831

832832
# realistic IRR
833-
internal_rate_of_return = internal_rate_of_return[internal_rate_of_return >= -1]
833+
eirr = eirr[eirr>=-1]
834834

835835
# if no real solution
836-
if len(internal_rate_of_return) == 0:
836+
if len(eirr) == 0:
837837
if raise_exceptions:
838838
raise NoRealSolutionError("No real solution is found for IRR.")
839839
return np.nan
840840

841841
# if only one real solution
842-
if len(internal_rate_of_return) == 1:
843-
return internal_rate_of_return[0]
842+
if len(eirr) == 1:
843+
return eirr[0]
844844

845845
# below is for the situation when there are more than 2 real solutions.
846846
# check sign of all IRR solutions
847-
same_sign = np.all(internal_rate_of_return > 0) if internal_rate_of_return[0] > 0 else np.all(internal_rate_of_return < 0)
847+
same_sign = np.all(eirr > 0) if eirr[0] > 0 else np.all(eirr < 0)
848848

849849
# if the signs of IRR solutions are not the same, first filter potential IRR
850850
# by comparing the total positive and negative cash flows.
851851
if not same_sign:
852852
pos = sum(values[values>0])
853853
neg = sum(values[values<0])
854854
if pos >= neg:
855-
internal_rate_of_return = internal_rate_of_return[internal_rate_of_return >= 0]
855+
eirr = eirr[eirr>=0]
856856
else:
857-
internal_rate_of_return = internal_rate_of_return[internal_rate_of_return < 0]
857+
eirr = eirr[eirr<0]
858858

859859
# pick the smallest one in magnitude and return
860-
abs_internal_rate_of_return = np.abs(internal_rate_of_return)
861-
return internal_rate_of_return[np.argmin(abs_internal_rate_of_return)]
860+
abs_eirr = np.abs(eirr)
861+
return eirr[np.argmin(abs_eirr)]
862862

863863

864864
@nb.njit(parallel=True)

0 commit comments

Comments
 (0)