finance.js icon indicating copy to clipboard operation
finance.js copied to clipboard

IRR precision

Open vonba opened this issue 5 years ago • 1 comments

Hello!

I'm seeing a discrepancy calculating IRR compared to Excel. It isn't huge, but when annualising it is enough for it to be a problem.

Consider the following code.

cashFlow = [-206136.99, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 8993.21, 18993.21];
// Calculate monthly IRR
IRR = finance.IRR( { depth: 1500, cashFlow: cashFlow } );
// Annualise IRR
IRR = (Math.pow(1 + IRR / 100, 12) - 1) * 100;

This returns 0.72% (exactly) which annually becomes 8.99% (8.990490026994502). Compared to Excel which gives me 0.71414% monthly and 8.91% annually (0.0891443135).

I would appreciate any clues as to why this is happening. I find the exact 0.72 a bit suspicious, is it possible that some rounding is happening there?

Cheers!

vonba avatar Sep 27 '19 23:09 vonba

Wasn't happy with the IRR result from this lib either. Found a fork which returns better results https://github.com/kgkars/tvm-financejs According to the readme it's tested to be correct against Microsoft Excel for Office 365 from March 2020

egodigitus avatar Jun 03 '20 08:06 egodigitus