@Jonah

These are rather trivial FV, PV and PMT function based on the ln1(x) function that was given by the author

I tested FV, PV and PMT functions using the secondly compounding of interest and the results are correct

The output

Code:

FV(i=3.170979198376459e-9 n=31536000 pmt=-0.01 pv=0 type=0) = 331667.0066907767
FV(i=3.170979198376459e-9 n=31536000 pmt=-0.01 pv=0 type=1) = 331667.0077424859
PV(i=3.170979198376459e-9 n=31536000 pmt=-0.01 fv=331667.0077424859 type=1) = 0
PV(i=3.170979198376459e-9 n=31536000 pmt=-0.01 fv=331667.0077424859 type=1) = 0
PMT(i=3.170979198376459e-9 n=31536000 pv=0 fv=331667.0077424859 type=1) = -0.01
PMT(i=3.170979198376459e-9 n=31536000 pv=0 fv=331667.0077424859 type=1) = -0.01

The JavaScript code

Code:

i = 0.1/31536000;
n = 31536000;
pv = 0;
pmt = -0.01;
atype = 0;
fv = FV(i,n,pmt,pv,atype);
document.write("FV(i="+i+" n="+n+" pmt="+pmt+" pv="+pv+" type="+atype+") = "+fv);
document.write("<br/>");
atype = 1;
fv = FV(i,n,pmt,pv,atype);
document.write("FV(i="+i+" n="+n+" pmt="+pmt+" pv="+pv+" type="+atype+") = "+fv);
document.write("<br/>");
pv = PV(i,n,pmt,fv,atype);
document.write("PV(i="+i+" n="+n+" pmt="+pmt+" fv="+fv+" type="+atype+") = "+pv);
document.write("<br/>");
atype = 1;
pv = PV(i,n,pmt,fv,atype);
document.write("PV(i="+i+" n="+n+" pmt="+pmt+" fv="+fv+" type="+atype+") = "+pv);
document.write("<br/>");
pmt = PMT(i,n,pv,fv,atype);
document.write("PMT(i="+i+" n="+n+" pv="+pv+" fv="+fv+" type="+atype+") = "+pmt);
document.write("<br/>");
atype = 1;
pmt = PMT(i,n,pv,fv,atype);
document.write("PMT(i="+i+" n="+n+" pv="+pv+" fv="+fv+" type="+atype+") = "+pmt);
document.write("<br/>");
function ln1 (x)
{
var s = x;
var c = 2;
var t;
var s1;
if (Math.abs(x) >= 0.01) return Math.log(1+x);
x = -x;
t = x;
for (;;) {
t *= x;
s1 = s - t/c;
if (s1 == s) break;
c += 1;
s = s1;
}
return s1;
}
function FVIF(r, n)
{
if (r==0.0)
return 1.0;
if (n==0.0)
return 1.0;
return Math.exp(n * ln1(r));
}
function FVIFA(r, n)
{
if (r==0.0)
return 1.0;
if (n==0.0)
return 0.0;
return (FVIF(r,n) - 1.0)/r;
}
function FV(rate, nper, pmt, pv, atype) {
var fv = 0.0;
atype = (typeof atype !== "undefined") ? atype : 0;
return -pv * FVIF(rate, nper) - pmt * (1.0+rate*atype) * FVIFA(rate, nper);
}
function PV(rate, nper, pmt, fv, atype) {
atype = (typeof atype !== "undefined") ? atype : 0;
return ( -fv - pmt * (1.0+rate*atype) * FVIFA(rate, nper) ) / FVIF(rate, nper);
}
function PMT(rate, nper, pv, fv, atype) {
atype = (typeof atype !== "undefined") ? atype : 0;
return (-pv * FVIF(rate, nper) - fv)/((1.0+rate*atype) * FVIFA(rate, nper));
}