xirr icon indicating copy to clipboard operation
xirr copied to clipboard

Infinite loop

Open lucasmncastro opened this issue 4 years ago • 5 comments

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!

lucasmncastro avatar Sep 15 '20 22:09 lucasmncastro

Hey @lucasmncastro ! Did you manage to solve this problem? I have the same issue. Thanks!

fedetaladriz avatar Jan 06 '23 16:01 fedetaladriz

Hi @fedetaladriz , didn't. I gave up and figured out another way to solve my issue.

lucasmncastro avatar Jan 06 '23 19:01 lucasmncastro

"I gave up and figured out another way to solve my issue" What was the other way out ?

ausangshukla avatar Jul 29 '23 19:07 ausangshukla

Hi @thimmaiah , in my case we changed the business logic and removed the feature related to cashflow.

lucasmncastro avatar Jul 31 '23 11:07 lucasmncastro

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.

fedetaladriz avatar Jul 31 '23 12:07 fedetaladriz

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 avatar Jul 03 '24 22:07 matias-martini

@matias-martini Thank you. I've just updated the readme to point to your gem.

tubedude avatar Jul 04 '24 11:07 tubedude

@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 ❤️

matias-martini avatar Jul 04 '24 16:07 matias-martini