@@ -827,38 +827,38 @@ def irr(values, raise_exceptions=False):
827
827
# as eirr = g - 1 (if we are close enough to a solution)
828
828
829
829
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
831
831
832
832
# realistic IRR
833
- internal_rate_of_return = internal_rate_of_return [ internal_rate_of_return >= - 1 ]
833
+ eirr = eirr [ eirr >= - 1 ]
834
834
835
835
# if no real solution
836
- if len (internal_rate_of_return ) == 0 :
836
+ if len (eirr ) == 0 :
837
837
if raise_exceptions :
838
838
raise NoRealSolutionError ("No real solution is found for IRR." )
839
839
return np .nan
840
840
841
841
# 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 ]
844
844
845
845
# below is for the situation when there are more than 2 real solutions.
846
846
# 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 )
848
848
849
849
# if the signs of IRR solutions are not the same, first filter potential IRR
850
850
# by comparing the total positive and negative cash flows.
851
851
if not same_sign :
852
852
pos = sum (values [values > 0 ])
853
853
neg = sum (values [values < 0 ])
854
854
if pos >= neg :
855
- internal_rate_of_return = internal_rate_of_return [ internal_rate_of_return >= 0 ]
855
+ eirr = eirr [ eirr >= 0 ]
856
856
else :
857
- internal_rate_of_return = internal_rate_of_return [ internal_rate_of_return < 0 ]
857
+ eirr = eirr [ eirr < 0 ]
858
858
859
859
# 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 )]
862
862
863
863
864
864
@nb .njit (parallel = True )
0 commit comments