Code:

<script type="text/javascript">
var nper = [12,120];
var pmt = [9.03,10.61];
var pv = [-100,-1000];
var fv = 0;
var atype = 1;
var compounding = 1;
var frate = 0.04;
var rrate = 0.055;
var horizon1 = 120;
var horizon2 = 60;
var guess = 0.05;
document.write("<p>nper = [12,120]"+"<br/>");
document.write("pmt = [9.03,10.61]"+"<br/>");
document.write("pv = [-100,-1000]"+"<br/>");
document.write("fv = "+fv+"<br/>");
document.write("horizon 1= "+horizon1+"<br/>");
document.write("horizon 2= "+horizon2+"<br/>");
document.write("type = "+atype+"<br/>");
document.write("compounding = "+compounding+"<br/>");
document.write("finance rate = "+frate*100+"%<br/>");
document.write("reinvestment rate = "+rrate*100+"%<br/>");
document.write("guess = "+guess*100+"%</p>");
irr = tadIncRATE(nper,pmt,pv,fv,atype,compounding,guess);
ar = irr * 12;
arp = Math.round(ar * 10000)/100;
document.write( "<p>tadIncRATE(nper[], pmt[], pv[], fv, type, compounding, guess) = " + irr +"<br/>");
document.write( "Annual IRR = " + irr + " * 12" +"<br/>");
document.write( "Annual IRR = " + ar +"<br/>");
document.write( "Annual IRR = " + arp +"%</p>");
mirr = tadIncMIRR( frate, rrate, nper, pmt, pv, 1);
amirr = mirr * 12;
amirrp = Math.round(amirr * 10000)/100;
document.write( "<p>tadIncMIRR( finance rate = "+ frate*100 +"%, reinvestment rate= " + rrate*100 +"%, nper, pmt, pv, 1) = " + mirr +"<br/>");
document.write( "Annual MIRR = " + mirr + " * 12" +"<br/>");
document.write( "Annual MIRR = " + amirr +"<br/>");
document.write( "Annual MIRR = " + amirrp +"%</p>");
hrr = tadIncHRR( irr, rrate, horizon1, nper, pmt, 1);
ahrr = hrr * 12;
ahrrp = Math.round(ahrr * 10000)/100;
document.write( "<p>tadIncHRR( finance rate = irr= "+ arp +"%, reinvestment rate= " + rrate*100 + "%, horizon= " + horizon1 +", nper , pmt, 1) = " + hrr +"<br/>");
document.write( "Annual HRR = " + hrr + " * 12" +"<br/>");
document.write( "Annual HRR = " + ahrr +"<br/>");
document.write( "Annual HRR = " + ahrrp +"%</p>");
hrr = tadIncHRR( irr, rrate, horizon2, nper, pmt, 1);
ahrr = hrr * 12;
ahrrp = Math.round(ahrr * 10000)/100;
document.write( "<p>tadIncHRR( finance rate = irr= "+ arp +"%, reinvestment rate= " + rrate*100 + "%, horizon= " + horizon2 +", nper , pmt, 1) = " + hrr +"<br/>");
document.write( "Annual HRR = " + hrr + " * 12" +"<br/>");
document.write( "Annual HRR = " + ahrr +"<br/>");
document.write( "Annual HRR = " + ahrrp +"%</p>");
function tadAEY(r, c)
{
if (r==0.0)
return 0.0;
if (c==0.0)
return Math.exp(r) - 1;
else
return Math.pow(1.0+r*c, 1/c) - 1;
}
function tadFVIF(r, n, c)
{
c = (typeof c !== "undefined") ? c : 1;
if (r==0.0)
return 1.0;
if (n==0.0)
return 1.0;
return Math.pow(1.0+tadAEY(r,c),n);
}
function tadPVIF(r, n, c)
{
c = (typeof c !== "undefined") ? c : 1;
if (r==0.0)
return 1.0;
if (n==0.0)
return 1.0;
return Math.pow(1.0+tadAEY(r,c),-n);
}
function tadPVIFbar(r, n, c)
{
c = (typeof c !== "undefined") ? c : 1;
if (r==0.0)
return -n;
if (n==0.0)
return 0.0;
return -n * tadPVIF(r,n+c,c);
}
function tadPVIFA(r, n, c)
{
c = (typeof c !== "undefined") ? c : 1;
if (r==0.0)
return 1.0;
if (n==0.0)
return 0.0;
return (1.0-tadPVIF(r,n,c))/r;
}
function tadPVIFAbar(r, n, c)
{
c = (typeof c !== "undefined") ? c : 1;
if (r==0.0)
return 1.0;
if (n==0.0)
return 0.0;
return (r * -tadPVIFbar(r,n,c) - (1.0-tadPVIF(r,n,c)) )/(r*r);
}
function tadIncHRR( irr, rrate, horizon, nper, pmt, c)
{
c = (typeof c !== "undefined") ? c : 1;
npv = 0.0;
nhv = 0.0;
rrate /= 12.0;
for (j=0; j<nper.length; j++)
{
npv += pmt[j] * tadPVIFA(irr, nper[j], c);
nhv += pmt[j] * tadPVIFA(rrate, nper[j], c);
}
hrr = Math.pow(nhv/npv, 1.0/horizon)*(1+rrate) - 1
return hrr;
}
function tadIncMIRR( frate, rrate, nper, pmt, pv, c)
{
c = (typeof c !== "undefined") ? c : 1;
npv = 0.0;
nfv = 0.0;
T = 0;
frate /=12.0;
rrate /=12.0;
for (j=0; j<nper.length; j++)
{
if(nper[j] > T)
T = nper[j];
}
for (j=0; j<nper.length; j++)
{
npv += -pv[j];
nfv += pmt[j] * tadPVIFA(frate, nper[j], c) * tadFVIF(rrate, T, c);
}
mirr = Math.pow(nfv/npv, 1.0/T) - 1
return mirr;
}
function tadIncRATE( nper, pmt, pv, fv, atype, c, guess)
{
guess = (typeof guess === "undefined") ? 0.10 : guess;
fv = (typeof fv !== "undefined") ? fv : 0;
c = (typeof c !== "undefined") ? c : 1;
atype = (typeof atype !== "undefined") ? atype : 0;
var i;
var x = 0.0;
var x0 = guess;
var f;
var fbar;
for (i=0; i<100; i++)
{
f = 0;
fbar = 0;
for (j=0; j<nper.length; j++)
{
f += pv[j] + pmt[j] * tadPVIFA(x0, nper[j],c) + fv * tadPVIF(x0, nper[j],c);
fbar += pmt[j] * tadPVIFAbar(x0, nper[j],c) + fv * tadPVIFbar(x0, nper[j],c);
}
if (fbar == 0.0)
return null;
else
x = x0 - f/fbar;
if ( Math.abs(x-x0) < 0.000001 )
return x;
x0 = x;
}
return null;
}
</script>