jhs@MITRE-BEDFORD.ARPA (10/06/87)
Probably everybody who ever got a home computer must have written one of each of the following programs, but I thought a few readers of these postings might find them useful nevertheless, especially "APRPROG.BAS", which computes the effective Annual Percentage Rate of a loan. -John Sangster / jhs@mitre-bedford.arpa ------------------------------------------------------------------------------ MORTGAGE.BAS - Simple loan payment calculator. Given the Annual Percentage Rate of interest, the number of payments per year (normally 12), and the total number of PAYMENTS in which loan is to be paid off, returns the monthly payment amount. (E.g. for 30 years of monthly payments, there are 360 payments.) The above is obtained by "RUN" or GOTO 100. If you start the program instead with "GOTO 400", it prints, on your printer, a table of "dollars per thousand" loan amounts for a range of interest rates you select and for a set of convenient loan durations (15, 20, 25, 30 years). (C) 1987 by John H. Sangster, placed in the public domain for non-commercial use; all commercial rights reserved. -------------------C-u-t---h-e-r-e---f-o-r---MORTGAGE.LST--------------------- 100 PRINT "}" 110 PRINT "MORTGAGE CALCULATOR by JHS" 120 ? "Revised 10 August 1986":? 130 N=300:NOLD=300:REM 25 YEARS 140 PRINT "ANNUAL PERCENT INTEREST"; 149 TRAP 162 150 INPUT I:IF I>0 THEN GOTO 170 160 IF I>0 THEN GOTO 170 161 PRINT "I <=0, SO..." 162 END 170 IF I>=1 THEN GOTO 200 180 I=I*100:? "TIMES 100 ASSUMED" 181 GOSUB 320 200 PRINT "PAYMENT PERIODS/YEAR"; 205 TRAP 211 210 INPUT K:GOTO 220 211 ? "MONTHLY PAYMENTS ASSUMED":K=12:GOSUB 320 220 IF K<=0 THEN STOP 230 LET IP=I/(K*100):REM INT/PERIOD 240 PRINT "TOTAL NR OF PAYMENTS"; 245 NOLD=N:TRAP 255 250 INPUT N:IF N<=0 THEN STOP 251 GOTO 260 255 N=NOLD:? "ASSUMING N=";:? N:GOSUB 320 260 GOSUB 265:GOTO 270 265 LET R=IP/(1-(1+IP)^-N):RETURN 270 PRINT "MULTIPLIER=";R 279 TRAP 140 280 PRINT "AMOUNT BORROWED";:INPUT A 290 IF A<=0 THEN PRINT :GOTO 140 300 P=INT(A*R*100+0.5)/100:PRINT P 310 GO TO 279 320 SOUND 0,85,10,15:FOR J=1 TO 40:NEXT J:SOUND 0,0,0,0:RETURN 400 REM Print Table of $/1000 410 ? "Starting APR";:INPUT APR1 420 ? " Ending APR";:INPUT APR2 430 ? " Step in APR";:INPUT ASTEP 432 CLOSE #1:OPEN #1,8,0,"P:" 433 PRINT #1,," Dollars Per Thousand Per Month":PRINT #1," " 434 PRINT #1," ","APR"," 15 Years"," 25 Years"," 30 Years":PRINT #1 440 FOR APR=APR1 TO APR2 STEP ASTEP 450 IP=APR/(K*100):N=180:GOSUB 265:R15=R*1000:N=300:GOSUB 265:R25=R*1000 455 N=360:GOSUB 265:R30=R*1000:PRINT #1,,APR,R15,R25,R30 460 NEXT APR ------------------------------------------------------------------------------ APRPROG.BAS - Computes Annual Percentage Rate (APR) from amount of loan, number of monthly payments, and amount of monthly payment (principal plus interest). Uses functional iteration method based on Contraction Mapping Theorem. (C) 1987 by John H. Sangster, placed in the Public Domain for non-commercial use; all commercial rights reserved. --------------------C-u-t---h-e-r-e---f-o-r---APRPROG.LST--------------------- 100 REM Program to compute APR (Annual Percentage Rate) from loan amt A, Payment P, and nr of payments N. 110 ? "Truth-in-Lending Interest Rate" 120 ? "Calculator - JHS 28 July 1986" 130 ? :TRAP 600 140 ? "Loan Amount";:INPUT A:? "Monthly Payment";:INPUT P:? "Total Nr of Payments";:INPUT N 150 IF A=0 THEN ? "AMOUNT=0 - INTEREST IS UNDEFINED":GOSUB 1000:GOTO 140 155 PA=P/A:I=PA 160 FOR J=1 TO 100 170 IOLD=I 180 GOSUB 500 190 IF ABS(I-IOLD)/IOLD<1E-12 THEN 300 200 NEXT J 210 ? "No convergence!":GOSUB 1000:GOTO 140 300 ? "CONVERGED AFTER ";J;" ITERATIONS" 400 ? "APR=";I*1200;" PERCENT PER ANNUM" 410 ? :GOTO 140 500 REM Iteration to improve estimate of I: 510 I=PA*(1-(1+I)^(-N)) 520 RETURN 600 ? :? "Use BREAK to exit to BASIC.":? :GOTO 110 1000 SOUND 0,65,12,15:FOR I=1 TO 120:NEXT I:SOUND 0,0,0,0:RETURN ------------------------------------------------------------------------------ CHEKBOOK.BAS - Simple checkbook balancing aid. Nothing fancy, just does the dirty work. Main advantage over a calculator is that the program helps you keep your place by automatically incrementing the check number as you enter check amounts. (C) 1987 by John H. Sangster - Placed in the public domain for non-commercial use; all commercial rights reserved. ----------------------C-u-t---h-e-r-e---f-o-r---CHEKBOOK.LST------------------ 10 REM Simple Checkbook Program 11 REM JHS 06/08/86 Version 1.0 12 REM Command interpreter to be 13 REM added in later version. 15 DIM A$(40):TRAP 200:BAL=0 200 REM Startup Routines 220 DIM C(100):DIM D(300) 1000 REM F - Forward Balance 1005 TRAP 2000 1010 ? "Balance forward from prev stmt":INPUT BALF:BAL=BALF 2000 REM C - Enter Credit Items 2010 ? "Enter credit items (deposits,":? "interest, corrections etc.)," 2020 ? "followed by RETURN, or just RETURN":? "to end input.":NC=0 2030 FOR I=1 TO 100:INPUT A$:IF LEN(A$)=0 THEN GOTO 3000 2035 C(I)=VAL(A$) 2040 BAL=BAL+C(I):NC=I:NEXT I 3000 REM D - Debits: checks & charges 3010 ? "Enter debits(checks&charges)" 3020 ? "Start with checks, beginning with":? "check number";:NCHK=0 3025 TRAP 3030:INPUT A$:NCHK=VAL(A$):ND=0 3030 FOR I=1 TO 300:? NCHK;" ";:INPUT A$:IF LEN(A$)=0 THEN GOTO 4000 3040 D(I)=VAL(A$):BAL=BAL-D(I) 3050 ND=I:IF D(I)>=0 THEN NCHK=NCHK+1 3060 IF D(I)<0 THEN NCHK=NCHK-1 3070 NEXT I 4000 REM Final Output Section 4010 TC=0:TD=0 4020 IF NC>0 THEN FOR I=1 TO NC:TC=TC+C(I):NEXT I 4030 IF ND>0 THEN FOR I=1 TO ND:TD=TD+D(I):NEXT I 4090 ? "STARTING BALANCE WAS $";BALF 4100 ? "TOTAL CREDITS $";TC;" # ITEMS: ";NC 4101 ? "TOTAL DEBITS $";TD;" # ITEMS: ";ND 4102 ? "ENDING BALANCE IS $";BAL:? :? 4110 ? "DO NEXT MONTH";:INPUT A$:IF A$(1,1)="Y" THEN BALF=BAL:GOTO 2000:END ------------------e-n-d---o-f---s-i-l-l-y---p-r-o-g-r-a-m-s-------------------