peliot / XIRR-and-XNPV

python implementation of Microsoft Excel's XNPV and XIRR
53 stars 23 forks source link

Doesn't work for negative XIRR #2

Closed justchells closed 10 years ago

justchells commented 10 years ago

If the XIRR is negative, the function fails with an error -

ValueError: negative number cannot be raised to a fractional power

For a sample test case, try giving the first 6 months as (-1000), and the last entry as 4,500.

peliot commented 10 years ago

Sorry for the slow response here- I wasn't checking this email as often as I should. In any case, there is no bug. The behavior is consistent with open office calc, which is what I have used to benchmark against. Both will fail on those values with the default guess of 0.1. If you add the optional guess argument and use a guess like -0.5, it should work correctly. It just doesn't converge fast enough with a starting guess if 0.1 for some negative values. I will be checking this email regularly now so feel free to follow up with any additional questions.

Regards, Philip

If the XIRR is negative, the function fails with an error -

ValueError: negative number cannot be raised to a fractional power

For a sample test case, try giving the first 6 months as (-1000), and the last entry as 4,500.

— Reply to this email directly or view it on GitHub https://github.com/peliot/XIRR-and-XNPV/issues/2.