The time value of money
Money now is worth more than the same money later, by the interest it could earn in between. Everything else in finance is built on moving amounts along the time line at a rate.
compound(1000, "5%", 10); // 1000·1.05¹⁰, exact
compound(1000, "5%", 10, { periodsPerYear: "continuous" }); // 1000·e^0.5, an interval
effectiveRate("12%", 12); // 1.01¹² − 1, exact
annuity({ payment: 100, rate: "5%", periods: 10 }).presentValue;
tvm({ pv: 200000, fv: 0, rate: "0.5%", n: 360 }).pmt; // −1199.10…, exact
tvm({ pv: -1000, fv: 2000, pmt: 0, rate: "7%" }).n; // how long to double: an interval
Interest
Simple interest on a principal P at rate r for time t is . Compound interest adds the interest to the principal each period, so after n periods at rate i per period the amount is . A nominal annual rate j compounded m times a year means per period, and letting m grow without bound gives continuous compounding, .
With a whole number of periods is a fraction and compound returns it exactly. With a fractional number of periods, or continuously, the value is irrational and comes back as an interval that contains it.
Equivalent rates
Rates that give the same growth over a year are equivalent. The effective annual rate of j compounded m times is ; 12% compounded monthly is 12.6825…% effective. Going the other way needs an m-th root, so nominalRate is exact only when the root is (21% effective is exactly 20% compounded twice a year, since ). equivalentRate(j, from, to) restates a rate at another compounding frequency, and realRate(nominal, inflation) is Fisher's , not the approximation .
Annuities
A level payment P at the end of each of n periods has present value
the sum of a geometric series. Paid at the start of each period (an annuity due) it is worth times as much. If each payment is times the last the ratio of the series changes to , and when every payment has the same present value. A perpetuity, with no last payment, is worth , provided . annuity handles all of these and a deferral, exactly.
Solving for what is missing
tvm is the equation behind a financial calculator's five keys,
with money received positive and money paid negative. Leave one out. PV, FV and PMT are solved exactly. The number of periods is a logarithm, returned as an interval (or exactly when it is whole) with whole, the number of periods actually needed. The rate is a root of a polynomial of degree n; every root above −100% is found and proven, and when it is a rational number, as a typed-in rate always is, it is returned as that fraction.
| call | returns |
|---|---|
| simpleInterest(P, r, t) | { interest, total } |
| compound(P, rate, years, { periodsPerYear }) | exact, or an interval |
| effectiveRate, nominalRate, equivalentRate, realRate | exact, or an interval |
| presentValue(fv, rate, n), futureValue(pv, rate, n), discountFactor(rate, n) | exact for whole n |
| annuity({ payment, rate, periods, due, growth, deferred }) | { presentValue, futureValue, total, payments } |
| perpetuity({ payment, rate, growth, due, deferred }) | Rational |
| tvm({ pv, fv, pmt, rate, n, due }) | the missing one: { pv } , { fv }, { pmt }, { n, whole, exact } or { rates, rate, count } |
@ratmath/finance and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.