xirr
xirr copied to clipboard
Infinite loop
Hey there!
Could you explain why the following code enter in infinite loop?
cf = Xirr::Cashflow.new
cf << Xirr::Transaction.new(-1, date: '2019-09-25'.to_date)
cf << Xirr::Transaction.new(-1, date: '2020-02-26'.to_date)
cf << Xirr::Transaction.new(-1, date: '2020-02-28'.to_date)
cf << Xirr::Transaction.new(1 , date: '2020-03-23'.to_date)
cf.xirr
Curiously, if I remove any transaction, it will work.
I noticed the issue occours in Newton#nsolve of ruby library.
Thanks!
Hey @lucasmncastro ! Did you manage to solve this problem? I have the same issue. Thanks!
Hi @fedetaladriz , didn't. I gave up and figured out another way to solve my issue.
"I gave up and figured out another way to solve my issue" What was the other way out ?
Hi @thimmaiah , in my case we changed the business logic and removed the feature related to cashflow.
The newton method enters in an infinite loop with certain sets of cashflows. It is not a bug of this library. Instead, it is a mathematical constraint.
We managed this case by setting a timeout for the calculation of 1 sec.
We faced a similar issue and ended up creating our own gem for calculating XIRR (using Brent on C instead of Newton), which you can find here.
@matias-martini Thank you. I've just updated the readme to point to your gem.
@tubedude thank you for updating the readme to include our gem. I also wanted to express my gratitude for the XIRR gem you've maintained over the years. It has been invaluable to us, and we greatly appreciate your work and dedication ❤️