File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -741,9 +741,19 @@ def irr(values, guess=0.1):
741
741
if values .ndim != 1 :
742
742
raise ValueError ("Cashflows must be a rank-1 array" )
743
743
744
- # NPV = V0 * (1+eirr)^0 + V1 * (1+eirr)^-1 + ...
745
- # let x = 1 / (1+eirr)
746
- # NPV = V0 * x^0 + V1 * x^1 + ...
744
+ # We aim to solve eirr such that NPV is exactly zero. This can be framed as
745
+ # simply finding the closest root of a polynomial to a given initial guess
746
+ # as follows:
747
+ # V0 V1 V2 V3
748
+ # NPV = ---------- + ---------- + ---------- + ---------- + ...
749
+ # (1+eirr)^0 (1+eirr)^1 (1+eirr)^2 (1+eirr)^3
750
+ #
751
+ # by letting x = 1 / (1+eirr), we substitute to get
752
+ #
753
+ # NPV = V0 * x^0 + V1 * x^1 + V2 * x^2 + V3 * x^3 + ...
754
+ #
755
+ # which we solve using Newton-Raphson and then reverse out the solution
756
+ # as eirr = 1/x - 1 (if we are close enough to a solution)
747
757
npv_ = np .polynomial .Polynomial (values )
748
758
d_npv = npv_ .deriv ()
749
759
x = 1 / (1 + guess )
You can’t perform that action at this time.
0 commit comments