Connecting Tech Pros Worldwide Forums | Help | Site Map

Calculating IRR's in Ruby

Newbie
 
Join Date: Oct 2007
Posts: 1
#1: Oct 26 '07
Hi - does anyone know of a good way of calculating an IRR (internal rate of return) from a (variable length) series of cash flows. I need it to be reasonably efficient. I know that it will have to be an iterative solution.

bugQ's Avatar
Newbie
 
Join Date: Jan 2008
Posts: 1
#2: Jan 29 '08

re: Calculating IRR's in Ruby


http://pastie.org/144919

I just wrote it this morning in 15 min. or so, using the trial-and-error model. It can find the IRR for 100 cash flows to 9 decimal places in about 23ms on my 17" MacBook Pro.

Note that this algorithm is O(n^2), i.e. doubling the length of the input array will roughly quadruple the computation time.

EDIT: Ack! Wait, don't use this. It only goes up to 100%. IRR can go past that, can't it? Give me a sec...

EDIT2: Okay, it's fine now, and probably a bit faster, too.
Reply