Most manufacturers of large computers (mainframes and minicomputers) offer a set of “utility” programs either as a freebie with purchase of their computer, or as a low cost option. One program that inevitably shows up in those packages is a loan amortization program for calculating monthly payments and an amortization schedule on consumer loans or home mortgages. The usefulness of such information is obvious. The payment tells the user how much of a monthly commitment he is making, and the amortization schedule how much of the payment is being applied to interest and how much to reduce the balance on the loan.
Most loan amortization programs ask the user to specify three out of the following four items of information: the amount of the loan (the principle), the annual interest rate, the duration of the loan, and the amount of each payment. The program then calculates the missing variable and prints out the amortization schedule. Usually that is printed out in a columnar format with the payment number in one column and the following items in the other columns: the payment amount, the amount of the payment that went for interest, the amount that went towards repayment of the principle, and the remaining balance on the principle.
Since I have a ZX80 (8K ROM) with only 1K of user memory, I knew that I would not be able to deal with a lot of options, nor would I be able to do an entire amortization schedule. I decided that the operator would supply the loan amount, the interest rate, and the number of monthly payments. The program would calculate only the payment necessary to amortize the loan. If I had room left over after the basic program was coded, I would see what could be done about an amortization schedule.
I first needed to find a formula for calculating the equal loan payments needed to amortize a loan. Such a formula can be found in virtually any consumer or practical mathematics textbook at your local library. That formula is seen cn Figure 1.
Figure 1. Loan Repayment Formula.
periodic int. rate
payment = loan amount X ------------------------------------------
1
1- ---------------------------------
(1 + periodic int. rate) periods
Before I started programming, I verified the formula by calculating a payment using a calculator and comparing the result with the payment amount listed in a loan payment book.
With a formula in hand, it was easy to come up with the statements needed to ask for input from the operator and to calculate the periodic interest rate. Those steps are handled in lines 10 through 70 of the program (shown in Figure 2). As shown, the information input by the operator is printed out as soon as it is entered to form a record of the loan parameters and as a convenience to the operator.
The periodic interest rate is found by dividing the annual interest rate by the number of payment periods in a year (the program assumes 12 payments per year). That interest rate indicates how much interest applies to each monthly payment.
Calculating the monthly payment, however, was a trickier problem. When I first wrote the program, I tried entering the payment calculation in one long program statement in algebraic format:
LET PAYMENT = P * I/(1-(1/(1+I)**MO))
Besides the obvious difficulty in trying to get a valid statement with so many parentheses, I also was getting the wrong answers because of the priority in which the ZX80/81 handles calculations (first exponentiation, then multiplication and division, and finally addition and subtraction). This produces wrong answers even though the formula is algebraically correct.
I decided to simplify the calculations, and also to get them in the proper sequence for calculation by first calculating the divisor of the formula as shown in the series of steps in lines 80, 90, and 100. Then, after I had the divisor, I could use a more simplified formula to calculate the monthly payment, as shown in line 110.
Lines 120, 130, and 140 print out the calculated monthly payment and then the headings for an amortization schedule. With a little experimentation, I discovered that I would have enough memory left over to show the amortization of one payment. Line 145, therefore, sets the payment number equal to 1. That is followed by calculation of the interest paid in the period, the reduction to the principle, and the balance remaining on the principle. For those with more memory, line 145 would be the appropriate place to start a FOR/NEXT loop to calculate a complete schedule. Just let the loop count equal the number of monthly payments (“MO”) and execute lines 150, 160, 170, and 190 on each pass through the loop. Specifically, the NEXT statement in the loop would go on a line after line 190.
Figure 2. Loan Amortization Program (1K).
10 PRINT "AMOUNT OF LOAN?"
20 INPUT AMT
25 PRINT AMT
30 PRINT "ANNUAL INTEREST RATE?"
40 INPUT RAT
45 PRINT RAT
50 PRINT "LOAN DURATION (MONTHS)?"
60 INPUT MO
65 PRINT MO
70 LET INT=(RAT/100)/12
80 LET DIVISOR=1+INT
90 LET DIVISOR=DIVISOR**MO
100 LET DIVISOR=1-(1/DIVISOR)
110 LET P=AMT*(INT/DIVISOR)
120 PRINT "PAYMENT=";P
130 PRINT
140 PRINT "NO. INT PAID REDUCTION BALANCE"
145 LET I=1
150 LET INTPAID=AMT*INT
160 LET RED=P-INTPAID
170 LET AMT=AMT-RED
190 PRINT I;" ";INTPAID;" ";RED;" ";AMT
Figure 3. Sample Run (1K).
AMOUNT OF LOAN? 4000 ANNUAL INTEREST RATE? 16 LOAN DURATION (MONTHS)? 48 PAYMENT=113.36112 NO. INT PAID REDUCTION BALANCE 1 53.333333 60.027791 3939.9722
Figure 4. Sample Run (over 1K).
1 53.33 60.03 3939.97 2 52.53 60.83 3879.14 3 51.72 61.64 3817.5 4 50.9 62.46 3755.04 5 50.07 63.29 3691.75 6 49.22 64.14 3627.61 7 48.37 64.99 3562.62 8 47.5 65.86 3496.76 9 46.62 66.74 3430.02 10 45.73 67.63 3362.39 11 44.83 68.53 3293.87 12 43.92 69.44 3224.42
Figure 5. Additions to Figure 2 for over 1K RAM.
135 SCROLL
145 FOR I=1 TO 48
147 SCROLL
190 PRINT I;TAB 4;INT (INTPAID*100+.5)/100;TAB 13;INT (RED*100+.5)/100;TAB 23;INT (AMT*100+.5)/100
200 NEXT I
Figure 3 shows a sample run of the program with the operator entering the amount of the loan, the annual interest rate, and the loan duration. The program echoes each of those entries by printing them back out. Following entry of the loan duration, the program calculates and prints out the amount of the monthly payment and then the one month amortization. As you can see, a good project for those with more memory would be a routine to round off the results to two decimal places!
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.