Calculating IRR's in Ruby

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • avitus
    New Member
    • Oct 2007
    • 1

    Calculating IRR's in Ruby

    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
    New Member
    • Jan 2008
    • 1

    #2


    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.

    Comment

    Working...