Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRR calculation errors: Singular Jacobian matrix and Failed to reduce function values. #24

Open
bdeterling opened this issue Aug 30, 2013 · 3 comments

Comments

@bdeterling
Copy link

I've been getting this error on many different series. I've tried various versions of Ruby 1.9 and 2.0. 1.9 tends to hang whereas 2.0 errors out fairly quickly. I've tried these same calculations in both Excel and the Java Apache POI library and they return good values. Any ideas?

Some examples:

[-1,-2,0,5].irr.to_f
=> 0.24189656303203824

[-1,-3,0,5].irr.to_f
RuntimeError: Failed to reduce function values (newton.rb:66 in nlsolve)

[-13000,-3000,-3000,0,0,5000,10000,20000].irr.to_f
RuntimeError: Singular Jacobian matrix. No change at x[0](jacobian.rb:58 in dfdxi)

@tubedude
Copy link

tubedude commented May 8, 2014

I've added a pull request that adds a guess param to IRR and XIRR.
#30

The error I mentioned was solved by:

[-13000,-3000,-3000,0,0,5000,10000,20000].irr(0.5).to_f
# => 0.10803084598726499

@marksweston
Copy link
Owner

@tubedude as you've closed your own pull request rather than merge it in, I get the impression this is still an open issue. So what next?

@tubedude
Copy link

tubedude commented Dec 2, 2015

Yes. I can try to work on a better implementation. My solution is to guess an IRR and add this guess to the XIRR method.
Today the XIRR method takes 1.0 as the initial guess which can leads to error like these.
What do you think about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants