public static async IRRCalc(CArray: string | any[], guest: number) {
const inc = 0.000001;
let NPV;
do {
guest += inc;
NPV = 0;
for (let j = 0; j < CArray.length; j++) {
NPV += CArray[j] / Math.pow(1 + guest, j);
}
} while (NPV > 0);
console.log('2222222222');
return guest * 100;
}
i am using below function IRR calculation by passing my cashflow and guess value 0.001 .i am not getting exact output as my excel is calculated my excel IRR formula is =IRR(G$26:G$386,0.01)*12
my cashflow input is [-150000,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,659.75,1009.75]}
the excel output is 2.36,but why my code is giving 2.336.
can anyone suggest please?
so i have tried changing the floting point numbers like gess value to IRRCalc(IRRval, 0.001)
//to
IRRCalc(IRRval, 0.0001)
inc = 0.000001;
//to
inc = 0.00000001 and followed the example from Javascript IRR (Internal rate of return) Formula Accuracy but no solutions i found to make my output same as exell