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

XIRR incorrect values for very large datasets

Open harzkr opened this issue 4 years ago • 2 comments

XIRR value is being calculated incorrectly for transactions of order 40k-50k, the incorrectness increases when the number of transactions increase say 80k-90k

This I had checked with other xirr packages which were returning the same value as well as Excel, which confirmed the calculations. The value calculated by this package was incorrect

harzkr avatar Apr 23 '20 04:04 harzkr

I can confirm this issue. Sample code:

const Finance = require('financejs');
var finance = new Finance();
var start = new Date(Date.parse("2013-12-31"));
var end = new Date(Date.parse("2014-05-15"));
var irr = finance.XIRR([-37987348, 21191041], [start, end], 0);
console.log(irr);    //will not calculate

However, if you (somehow) correctly guess the initial guess close to the result, it will work.

var irr = finance.XIRR([-37987348, 21191041], [start, end], -0.8);
console.log(irr);    //-79.36

@harzkr did you find a solution to your problem?

jadfls avatar Oct 21 '20 18:10 jadfls

Hi @jadfls

Nice find on the guess value part that you mentioned, but yeah it does pose the difficulty of correctly assuming an initial close value.

I have kept the usage of this package limited to any fallback calls(if others fail), and have shifted my primary package to webcarrot/xirr, which is based on the XIRR function call from the LibreOffice Software

Since it is closely associated with the MS Office Excel etc., softwares, it correctly calculates values for 99.9% of the use cases, for others, there's usually a problem with improper set of transactions, else, I use fallback calls to this and other XIRR packages to get a value. But mostly those are very corner cases

harzkr avatar Oct 30 '20 18:10 harzkr