Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

error in financial.npv ? #453

Closed
ghost opened this Issue · 2 comments

1 participant

@ghost

Contrary to what the doc says, the sum is done from t=1 to M.
I'm not a finance expert, but it seems wrong to me, and I would tend to agree with the doc.
As for the financial.irr function, it returns the right result.

Correct code would be:

values = np.asarray(values)
return (values / (1+rate)**np.arange(0,len(values)).sum(axis=0)
@ghost ghost closed this
@ghost ghost reopened this
@ghost

I don't understand your point, the documentation is incorrect in that it should have a t+1 exponent (and possible M-1 in the sum)
math :: \sum_{t=0}^{M-1}{\frac{values_t}{(1+rate)^{t+1}}}. The code seems correct your code has the first exponent as 0, when it is 1 if you do a sum from t=1 to M.

Sorry, my bad, I didn't pay attention, the index in the documentation was wrong too.
The sum should go from 0 to M-1 indeed. math :: \sum_{t=0}^{M-1}{\frac{values_t}{(1+rate)^t}}
I don't see why you would change the exponent into t+1 though, t is valid as is as far as I understand, since the first value is considered as the initial investment, no interest should be applied anyway.
Similarly, the doc string in finance.irr should also be corrected into a sum from 0 to M-1.

@seberg
Owner

npv was fixed/changed with Numpy 1.8.x.

@seberg seberg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.