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\
This might be a better way of writing the calculation. This allows the code to calculate instances of negative IRR or IRR above 100%.
var IRRval = [];
IRRval.push(-financed);
for (i = 0; i < period; i++) {
IRRval.push(rental);
}
var IRR = IRRCalc(IRRval, 0.001) * 0.01;
function IRRCalc(CArray) {
var r = 0
min = -1.0;
max = 10000.0;
do {
guest = (min + max) / 2;
NPV = 0;
for (var j = 0; j < CArray.length; j++) {
NPV += CArray[j] / Math.pow((1 + guest), j);
}
if (NPV > 0) {
min = guest;
}
else {
max = guest;
}
r++
} while (r < 100);
return guest * 100
}