# Programming the TI

## C. Regena

### An Amortization Schedule

Interest rates have been plunging lately, and it seems like home mortgages and refinancing are very popular topics for newspaper articles. Recently I was reading a question-and-answer article in which the reader asked for a program for his home computer to print an amortization schedule for a home mortgage. The columnist suggested a particular program which was easy to use and costs only $99.I couldn't believe someone would spend $99 for a program that uses one or two basic computations! So, for the price of this magazine, here is such a program: "Loan Amortization."

It's certainly easy to use. Just enter the amount of money you want to borrow, omitting the dollar sign and comma (i.e., type 50000 instead of $50,000). Next, enter the interest rate, such as 13 for 13 percent or 9.5 for nine and a half percent. Finally, enter the number of years for the loan. Most loans are for a certain number of whole years, such as 25 or 30, so this program is based on 12 monthly payments per year rather than calculating a number of months. The program then tells you what your monthly payment will be. (Of course, this figure doesn't include property taxes, insurance, or condominium fees.)

You may then choose to see the amortization schedule on the screen or print out a paper copy. If you have a printer, be sure to use the correct printer configuration in line 710, the OPEN statement. If you don't want to see the amortization schedule, you may calculate another loan or end the program.

#### Converting Math To BASIC

Among other things, Loan Amortization demonstrates how easy it can be to convert a mathematical formula into a BASIC program. Any ordinary formula can be converted by using the + and - signs for addition and subtraction, the * sign for multiplication, / for division, and sets of parentheses where necessary to group mathematical operations.

Use PRINT and INPUT statements to prompt numbers from the user. You may want to use some IF-THEN statements to make sure the INPUT values are within reasonable limits for the formula. In Loan Amortization, all numbers entered must be positive. The amount of the loan has to be six digits or less (not counting the cents) to help limit the printing variables. The number of years is from 1 to 50.

Once your program has all the numbers it needs, calculate the formula and PRINT the answer. The computer, of course, is ideal for handling repetitious calculations, such as this amortization schedule.

Any economics book has formulas for various calculations involving money—savings accounts, sinking fund deposits, present worth factors, and so forth. In this case, to find the monthly payment I used the capital recovery factor formula:

I(1+I)^N/(1+I)^N-1

where *I* = interest and *N* = the number of payments. To make it easier to type the program without errors, I used the variable D for interest, since the letter I can be confused with the numeral 1. Then the program converts the percentage to a monthly decimal, J=D/1200. The factor with the exponent is used twice, so I calculated it as F in line 490. Line 500 then calculates the capital recovery factor, CRF.

#### How To Pause Printing

The FOR-NEXT loop in lines 800-1050 prints the amortization schedule with the monthly payment PAY. Part of the payment goes to principal (the variable PR), and part is interest (the variable II). The balance is the original principal minus the principal part of the payment, P. Lines 1060-1200 calculate and print the last payment, which may be slightly different than the regular monthly payment because of rounding to the cent.

The printing on the screen includes only the month number, principal and interest, then balance. To pause the printing while it is scrolling, hold down any key. When you release the key, the schedule will continue. To make this work, lines 1010-1040 scan the keyboard in each loop. If a key is not pressed, the program goes to the next calculation. You may want to print different items or adjust the printing to better suit your needs.

All of the PRINT # statements send text to the printer. The variables L1, L2, and L3 are lengths used in the TAB functions to line up the columns. The variable R holds the user's choice: 1, 2, 3, or 4. If the choice is 1, the program skips all the statements that pertain to the printer.

The subroutine in lines 1250-1330 converts a number in the variable A to a string so that a number can be written in money form with two decimal places (using zeros where necessary). The numbers are rounded to the nearest cent.

If you have TI Extended BASIC or are converting this program to another version of BASIC, PRINT USING would be easier to use than this subroutine. For example, PRINT USING ####.## will round a number to two decimal places and will also right-justify numbers for printing straight columns.