Authors
Publication
Publication Details
Volume: 3 Issue: 6
Date
Pages
Turning Tables on the Bank
After a short vacation changing jobs, being confronted with a company-wide layoff at my new job, leaving after only three months for my current job, and becoming engaged to a girl who thinks microbiology is fun, I returned to the important things in life — home computers.
Like the traditional young couple in suburbia, my financee and I are looking to buy a house. But calculating mortgage rates and monthly payments is an awful pain. Luckily, affordable calculators have recently become available that will do these calculations. But if you do not mind sacrificing portability, your ZX81/TS1000 will do an admirable job.
A mortgage is simply an annuity, only backwards— somewhat. An annuity is a lump sum of money, earning interest at some rate, which is being drawn upon at a regular rate, until it is used up. In the genera! case, you would deposit some amount of money into a bank account and make equal monthly withdrawals until the account was empty.
The four components of an annuity are the payment, present value, interest rate, and number of payments. Most business calculators will compute any of the four, given the other three. (There is a fifth component, called the future value, but it is of no interest in calculating mortgages.)
The payment is the amount of the regular withdrawal from the annuity. In the case of a mortgage, it is the amount of the monthly mortgage payment. Most business calculators have a key marked “PMT” for this value.
The present value of an annuity is its initial amount. In other words, the amount you initially deposited in the bank, or the amount that you borrowed from the bank, in the case of a mortgage. Most business calculators have a key marked “PV” for this value.
The interest rate is the periodic interest rate for the period between payments. For a 12% APR (annual percentage rate) mortgage, this interest rate would be 0.12 only if mortgage payments were being made annually. In general, mortgage payments are made monthly and the interest rate is therefore divided by 12. Most business calculators have a key marked “i” for the interest rate.
The number of periods is simply the number of withdrawals that can be made, or the number of mortgage payments that must be made, before the annuity is used up. Most business calculators have a key marked “n” for this value.
Since single letter variable names tend to work better with tiny computers, I have chosen to use the single letter “P” to represent the payment (“PMT”) and the single letter “V” to represent the present value (TV”). The interest rate and number of payments will remain “I* and “N”, respectively.
Opening up my college accounting textbook (I had to open it eventually) we see that the present value, V, of an annuity is given by the formula.
V=P/I [1-1/(1+I)N]
or, in Basic syntax:
V=(P/I)*(1-(1/(1+I)**N)
A little algebraic manipulation gives us the comparable formula for the amount of the payment, P:
P=(V*I)/(1/(1+I)**N)
Isolating N on one side of the equation gives us:
V*I/P=1-(1/(I+I)**N)
1/(1+I)**N=1-V*I/P=(P-V*I)/P/P
(1+I)**N=P/(P-V*I)
Now we take the logarithm of each side of the equation (bet you never thought you’d actually have a use for the “LN” function):
N*LN(1 + I) = LN(P/(P-V*I))
And finally, the equation for the number of payments:
N=LN(P/(P-V*I))/LN{1 + I)
According to my future father-in-law, there is no simple equation for directly computing the interest rate given the other three values (and it is the smart finance who listens to his future father-inlaw— at least until after the wedding). Business calculators compute this value by any number of approximation methods. I chose to use a simple binary chop, as it is both easy to write and to understand.
Now that we have methods for computing each of the four values, given the other three, let’s build a program to use them.
On the typical business calculator, the four keys, PMT, PV, i, and n each serve two purposes. First, you enter a value by keying in a number and then pressing the appropriate key. To compute one of the values once the others have been entered, you press “shift” (“2nd” “f ,” or whatever) and then the key of the value you want to compute. The program following this article works in much the same way, except that you enter a value by first pressing the key for the value you want to enter, and then typing in the value, followed by ENTER.
As an example of how to use this program, let’s determine the monthly payment for a 30 year, 12.5% mortgage on $52,500. After running the program (in FAST mode), you will see the current values of the payment, present value, interest rate, and number of payments. Enter the present value (the amount of the mortgage) by pressing V. The cursor will appear at the bottom of the screen, waiting for you to type in a value. Type in “52500” and press ENTER, 52500 now appears on the screen as the present value.
The interest rate of 12.5% is an annual interest rate, but mortgage payments are made monthly, so enter the interest rate by pressing 1 and then typing in “.125/12” and pressing ENTER. The monthly interest rate appears on the left of the screen, with the yearly rate to the right of it.
30 years of monthly payments is 360 payments, so press N, type in “360”, and press ENTER.
Now that you have entered the other three values, you may compute the size of the payment. Press SHIFT-P (actually you are pressing “) and after a few seconds of thinking, you will see that the monthly payment, given these other factors, is $560.31.
Now, let’s say that you want to see what would happen if you borrowed $55,000 instead. Simply enter a new value for V and press SHIFT-P again. You can do this to compute any one of the four values (calculating I takes a little longer though).
The program itself is fairly straightforward. Lines 10-40 simply initialize the four values to zeros (a good idea in general). Lines 50-90 display the four values on the screen. Lines 100 and 110 wait for a key to be pressed (the use of the PAUSE statement like this is documented in chapter 19 of the original Sinclair manual and in chapter 16 in the Timex/Sinclair manual). Line 120 is simply a small space optimization since the expression
"l-(l/(l + I)**N"
is used in calculating both P and V. Lines 130-160 simply read in one of the four values, depending on which key was pressed, and lines 170-200 compute one of the four values, depending on which key was pressed.
The only lines that really need some explanation are 220-290, which compute the interest rate using a binary chop algorithm. A binary chop is a method of computing a value by making successive approximations, adjusting the approximation as needed, until the correct answer is determined. It is called a binary chop because at the outset it is known that the correct answer lies within a certain range, and with each approximation, this range is chopped in half, until only the correct answer is left.
In our example, it is clear that the lowest possible value for the interest rate is (line 220). It is also almost as clear that the highest possible value is P/V (line 230). If the interest rate were equal to P/V that would mean that the entire payment would be interest, with no payment to principal, and therefore the mortgage would never be paid off (actually, there are some variable rate mortgages available now where the monthly payment does not even cover the interest, but this program only works on mortgages that can eventually be paid off).
Now that we have the initial range, we compute the midpoint (line 240) and compute the monthly payment using this midpoint as the guess of the interest rate (line 250). Note that we can not use our value of D from line 120 in this case since I is changing. If the payment computed here equals the payment we entered earlier (to the accuracy of the machine), then we have arrived at the correct value of I and can return (line 260), If not, then we determine whether the correct answer lies in the upper or lower half of the range we just used, adjust the range accordingly (lines 270-280) and try again. If the payment we computed is less than the actual payment entered (line 170), then our guess for I was too low and the correct answer lies in the upper half of the range. Therefore, the lower bound (LI) is adjusted upward. If the payment computed is more than the actual payment (line 280) then the corect answer lies in the lower half of the range and the upper bound (HI) is adjusted. Eventually this range becomes small enough to return just a single value, which is our answer.