I\'m using a IRR function in javascript to create calculation a that is done in excel using its own IRR function. The problem is mine is little off and I have no idea why. Here\
Try this.
function NPV(discountRate, cashFlow){
var npv = 0;
for(var t = 0; t < cashFlow.length; t++) {
npv += cashFlow[t] / Math.pow((1+ discountRate),t);
}
return npv;
}
function IRR(cashFlow,guess){
guess = guess ? guess : 0.1;
var npv;
var cnt = 0;
do
{
npv = NPV(guess,cashFlow);
guess+= 0.001;
cnt++;
}
while(npv > 0)
return guess;
}