Financial Calculators · Volume 5

The Mathematics of Money

Nearly everything the 12C does with money comes down to one idea: a sum received later is worth less than the same sum now, because money now could be earning interest in the meantime. HP prints the formulas its calculator uses in Appendix D of the 12C user’s guide. This volume walks through them, shows how the calculator solves the one that has no formula, and ends with why ten-digit arithmetic needs care to get them right. Every number in the figures is computed from HP’s formulas, and those formulas reproduce HP’s printed answers exactly.

5.1 One equation, five keys

The five keys n, i, PV, PMT and FV are linked by a single equation. HP gives it on page 186 of the user’s guide:

0 = PV + (1 + iS) · PMT · [1 − (1 + i)⁻ⁿ] / i + FV · (1 + i)⁻ⁿ

Figure 1 — The time-value-of-money equation as HP prints it: each term tied to one of the five financial keys, and S to the BEGIN/END setting.
Figure 1 — The time-value-of-money equation as HP prints it: each term tied to one of the five financial keys, and S to the BEGIN/END setting. — Drawing: my own, from HP's 12c user's guide, Appendix D, p. 186.

Read term by term, it says that the present value, plus the present value of all the payments, plus the present value of what is left at the end, comes to nothing: the deal balances. Each term is brought back to today by dividing by (1 + i) once for every period it lies in the future. The bracket is the present value of n payments of 1, the annuity factor that Richard Witt tabulated in 1613. The factor (1 + iS) handles the payment timing: S is 0 when payments come at the end of each period and 1 when they come at the beginning, and a payment one period earlier is worth one period’s interest more.

The signs carry the direction of the money. Money received is positive and money paid out negative, which is why a loan’s PV and its PMT always have opposite signs and why the 12C’s users press CHS, change sign, so often. If all of PV, PMT and FV have the same sign there is no interest rate that balances them, and the 12C says so with Error 5.

Figure 2 — The loan on the back of my 12C as a cash-flow diagram: 50,000 received, then 360 monthly payments of 276.10 at the end of each month, or 274.90 at the start.
Figure 2 — The loan on the back of my 12C as a cash-flow diagram: 50,000 received, then 360 monthly payments of 276.10 at the end of each month, or 274.90 at the start. — Drawing: my own; payments computed from HP's equation.

Given any four of the five, the fifth follows. PV, PMT and FV appear in the equation only to the first power, so they come out by algebra. For n it takes a logarithm, and the 12C rounds the answer up to a whole number of periods, unless the fraction is under 0.005, in which case it rounds down (user’s guide, p. 40). For i there is no formula at all.

5.2 Amortization

A loan’s payment is the same each month, but its make-up changes. Each month the lender charges interest on the balance still owed, and whatever is left of the payment reduces the balance:

  • interest = balance × i, rounded;
  • principal = payment − interest;
  • new balance = old balance − principal.
Figure 3 — The 360 payments of the loan on my 12C's back label, each split into interest and principal: interest dominates for the first 202 payments.
Figure 3 — The 360 payments of the loan on my 12C's back label, each split into interest and principal: interest dominates for the first 202 payments. — Drawing: my own, computed from HP's amortization formula (user's guide, p. 186).

On the 30-year loan of 50,000 at 5.25 per cent printed on my calculator’s back, the first payment of 276.10 is 218.75 interest and only 57.35 principal, and the first year’s twelve payments pay 2,608.19 of interest against 705.03 of principal. Not until the 203rd payment does the principal share pass the interest. Over the whole loan the borrower pays 99,396.67, of which 49,396.66 is interest.

The 12C rounds each month’s interest to the number of decimal places on the display, as lenders round to the cent, and the rounding changes the number stored inside the calculator (user’s guide, p. 54). So a schedule worked with two decimal places shown can differ by a cent or two from one worked with four, which is why the guide asks for the display to match the lender’s practice.

5.3 Net present value and internal rate of return

For an investment whose returns are uneven, the 12C stores up to twenty cash flows, CF₀ to CF₂₀, each with a repeat count of up to 99, and works out the net present value at a chosen rate:

NPV = CF₀ + CF₁/(1 + i) + CF₂/(1 + i)² + … + CFₙ/(1 + i)ⁿ

A positive NPV means the investment beats the rate; a negative one that it falls short. The internal rate of return is the rate at which the NPV is exactly zero, the return the investment itself earns.

Figure 4 — NPV against interest rate for HP's property example: 907.77 at 13.5 per cent, zero at 13.72 per cent, the IRR. Inset: cash flows that change sign twice, with two IRRs, 25 and 400 per cent.
Figure 4 — NPV against interest rate for HP's property example: 907.77 at 13.5 per cent, zero at 13.72 per cent, the IRR. Inset: cash flows that change sign twice, with two IRRs, 25 and 400 per cent. — Drawing: my own, computed from the cash flows in HP's 12c user's guide, pp. 62–63.

HP’s example (user’s guide, pp. 62–63) is a property bought for 79,000 that returns 14,000; 11,000; 10,000 for three years; 9,100; 9,000 for two years; 4,500; and 100,000 when it is sold. At 13.5 per cent its NPV is 907.77, and its IRR is 13.72 per cent.

An IRR need not be unique. Each change of sign in the cash flows allows another place where the NPV can cross zero: an investment of 1,600 that returns 10,000 and then costs 10,000 has two internal rates of return, 25 and 400 per cent. HP’s guide warns of this (Appendix B, p. 179). If the 12C finds a positive answer, it is the only positive one; if the problem is too tangled it stops with Error 3 and asks for a guess, keyed in and followed by RCL g R/S, from which it searches again.

5.4 Searching for the rate

There is no formula for i. The equation is, in disguise, a polynomial of degree n in 1/(1 + i), and for degree five and above there is no general formula for the roots. Every financial calculator therefore searches: it guesses a rate, works out how far the equation is from balancing, adjusts the guess, and repeats. That is why the 12C flashes running while it finds i, an IRR or a bond yield.

Figure 5 — Finding the IRR of HP's property example: correct digits at each step of Newton's method and of the secant method. Newton's roughly doubles the correct digits each step once it is close.
Figure 5 — Finding the IRR of HP's property example: correct digits at each step of Newton's method and of the secant method. Newton's roughly doubles the correct digits each step once it is close. — Drawing: my own, computed.

HP’s first financial calculator, the HP-80, used Newton’s method. The Hewlett-Packard Journal of May 1973 printed its interest-rate routine: start from i₀ = 2(n − PV/PMT) / [n(n + 1)], a guess made from the first three terms of a binomial expansion, then repeatedly correct it by the equation’s error divided by its slope, “sawtoothing into the solution”. From a reasonable start, each step roughly doubles the number of correct digits. HP has not published the 12C’s own method; the algorithms of its financial calculators from the HP-92 of 1977 on are credited to William Kahan of Berkeley.

5.5 Bonds

A bond pays a coupon twice a year and its face value at maturity. The 12C prices it by the formula of the Securities Industry Association’s Standard Securities Calculation Methods (1973), which HP cites (user’s guide, pp. 66, 188): the present value of the redemption payment and of each remaining coupon, discounted at the yield, less the interest that has built up since the last coupon. The calculator counts actual days, the basis for United States Treasury bonds; other conventions need programs. Yield to maturity is the inverse problem, and like IRR it is found by searching.

The bond printed on my calculator’s back pays 4.75 per cent and matures on 15 November 2013, bought on 28 April 2004, 165 days into a coupon period of 182 days with twenty coupons to come. At a yield of 6 per cent it is worth 91.01 per hundred, plus 2.15 of accrued interest; priced at 99.16, it yields 4.86 per cent.

5.6 Depreciation and dates

The three depreciation keys follow the formulas accountants use (user’s guide, pp. 189–190):

  • straight-line: (cost − salvage) / life, the same each year;
  • sum-of-the-years’-digits: (cost − salvage) × (years remaining, counting this one) / (1 + 2 + … + life), front-loaded;
  • declining-balance: book value × factor / life, where a factor of 200 per cent gives “double declining balance”.

For the dates, the 12C converts each date to a day number with a formula that turns a “31 days in every month” count into the real calendar, f = 365 × year + 31 × (month − 1) + day + year/4 − a correction for the months after February, with further tests for century years (p. 187). Its calendar runs from 15 October 1582, the first day of the Gregorian calendar, to 25 November 4046. It can also count on the bond market’s 360-day year of twelve 30-day months, which is why the days between two dates come out as two numbers.

5.7 Why ten digits need care

The 12C works with ten significant digits. That is plenty for most arithmetic but not for compound interest done naively. To raise 1 + i to the power n, the obvious way is first to form 1 + i, and with a small rate most of the rate’s digits are lost in the rounding: at 10 per cent a year compounded every second, i is about 0.000000003, and 1 + i rounded to ten digits keeps only one of its significant figures.

Figure 6 — Left: (1 + 1/n)ⁿ computed with ten-digit rounding approaches e and then collapses to 1 at n = 10¹⁰. Right: the "penny a second" test, scored in correct digits, with the regular 12C at 10.6 and the …
Figure 6 — Left: (1 + 1/n)ⁿ computed with ten-digit rounding approaches e and then collapses to 1 at n = 10¹⁰. Right: the "penny a second" test, scored in correct digits, with the regular 12C at 10.6 and the faulty Brazilian firmware at 7.2. — Drawing: my own, computed; test scores from The Register, 21 September 2024.

The “penny a second” test makes the point. A penny deposited every second for a year, at 10 per cent compounded every second, comes to 331,667.00669. Worked naively with 1 + i rounded to ten digits, the answer is about 312,925, wrong in the second digit. A regular 12C, by Duncan Murray’s measurement reported in The Register, gets about 10.6 digits right, which it can do only by computing the growth through an accurate logarithm of 1 + i rather than through 1 + i itself. The technique, known from Kahan’s work and from HP’s handbook for the HP-15C, computes u = 1 + x and then ln(1 + x) as x · ln(u) / (u − 1), which cancels the rounding error made in forming u. The faulty Brazilian firmware of 2023 scored 7.2 on the same test; HP’s own HP-70 of 1974 scored 1.2.

Sources

  • HP, HP 12c financial calculator user’s guide, Edition 5 (2008): pp. 40, 54, 62–63, 66–68; Appendix B (pp. 179–180); Appendix D, “Formulas Used” (pp. 185–192).
  • W. L. Crowley and F. Rodé, Hewlett-Packard Journal, May 1973, Appendix A, “A Typical HP-80 Algorithm”.
  • Spence, Graudenz and Lynch, Standard Securities Calculation Methods (Securities Industry Association, 1973), as cited by HP.
  • D. Goldberg, “What Every Computer Scientist Should Know About Floating-Point Arithmetic” (Theorem 4, citing HP’s HP-15C Advanced Functions Handbook); The Register, “HP 12C calculator mystery”, 21 September 2024; Wikipedia, “Internal rate of return”.
  • The amortization schedule, NPV profile, iterations, bond price and (1 + 1/n)ⁿ values are my own calculations with HP’s formulas.

Comments (0)

  1. Loading…

Comments are held for moderation — nothing appears until approved.