100   ! THIS IS THE FINANCIAL COMPUTATION PROGRAMME
110   !
112   SIGNIFICANCE 11
115   E1$="###.#########"
116   STRSIZ 132
117   ?tab(-1,0)
118   ?tab(3,1)
120   ?"THIS PROGRAMME WILL COMPUTE THE FOLLOWING"
130   ?"             (1) AN ANNUITY-- EITHER A FUTURE VALUE OR"
140   ?"                 A PRESENT VALUE AND SOLVE FOR THE PAYMENT"
150   ?"                 THEN INTEREST RATE,THE NUMBER OF PERIODS,THE"
160   ?"                 PRESENT OR FUTURE VALUE,THE BALLOON PAYMENT"
170   ?"                 ON A LOAN,PRINT A LOAN SCHEDULE IF DESIRED AND"
180   ?"                 IT WIILL ALSO SOLVE PROBLEMS WHERE THE PAYMENTS"
190   ?"                 ARE RECEIVED IN ADVANCE"
200   ?" "
210   ?"             (2) A LUMP SUM- WILL SOLVE FOR THE FUTURE VALUE"
220   ?"                 THE PRESENT VALUE,THE INTEREST RATE OR THE"
230   ?"                 NUMBER OF PERIODS"
240   ?" "
250   ?"             (3) BONDS- WILL SOLVE FOR THE PRICE OF A BOND"
260   ?"                 OR SOLVE FOR THE YIELD TO MATURITY OF A BOND"
265   input "hit return to continue --> ", dummy$  :  ?
266   ?tab(-1,0)
267   ?tab(3,1)
270   ?"THE FOLLOWING NOTATION IS USED:"
280   ?"N=THE ACTUAL NUMBER OF PERIODS"
290   ?"PMT=THE $ PAYMENT PER PERIOD"
310   ?"PV=PRESENT VALUE"
320   ?"FV(BALLOON)=THE FUTURE OR BALLOON PAYMENT"
330   ?"IF YOU ARE SOLVING FOR A FUTURE VALUE ENTER '1' IN FOR FV"
340   ?"COMPOUNDING=THE NUMBER OF TIMES COMPOUNDING PER YEAR"
350   ?"TYPE=TYPE OF ANNUITY--ENTER '0' FOR A NORMAL ANNUITY,AND"
360   ?"A '1' FOR AN ANNUITY DUE(PAYMENTS ARE DUE AT THE BEGINNING OF"
370   ?"A PERIOD)"
380   ?" "
390   ?" "
400   ?" "
410   ?"************************************************************"
412   FNA2=0 : FNA3=0 : FNA4=0 : FNA5=0
420   FOR Z8=1 TO 3 : PRINT : NEXT Z8
430   ?"WHICH DO YOU WANT: (1) AN ANNUITY; (2) A LUMP SUM; "
440   ?"OR (3) A BOND CALCULATION"
450   K1=K2=C6=C9=0
460   INPUT K1
470   FOR J=1 TO 3 : PRINT : NEXT J
480   IF K1=1 THEN 510
490   IF K1=2 THEN 2370
500   IF K1=3 THEN 2460
510   ?
520   ?
530   ?"ENTER N,I,PMT,PV,FV(BALLOON),PMTS PER YR,TIMES COMPOUNDED PER YR,TYPE"
540   INPUT A,B,C,D,E,C5,F,K2
542   IF F<>C5 THEN GOSUB INTFAC
550   C3=B
560   C4=A
570   C1=C
580   C2=D
590   C6=E
595   GOTO 650
600 FUNCT:
602   FNA=INT(X*100+.5)/100
604   IF Y=0 OR Z=0 THEN 642
610   FNB=INT((1+Z/C5/100)**(-Y)*X*100+.5)/100
620   FNC=INT((1+Z/C5/100)**(Y)*X*100+.5)/100
630   FND=INT(((X/Y)**(1/(Z))-1)*10000*C5+.5)/100
640   IF X<>0 THEN FNE=INT((LOG(X/Y))/(LOG(1+Z/100/C5))+.5)
642 RETURN
650   IF E>0 AND K2=1 THEN E=E/(1+B/100/C5)
660   IF K2=1 AND D>0 AND B>0 THEN D=D/(1+B/100/C5)
670   ?
680   ?
690   !
700   !
710   ?
720   ?
730   ! CONVERTING INTEREST AND PERIODS TO ACTUAL PERIODS
740   ! AND THE ACTUAL INTEREST PER PERIOD
750   !
760   IF B>0 THEN B=B/C5
770   ! TEST TO SEE IF INTEREST IS THE DESIRED OUTPUT
780   IF B=0 THEN 1440
790   IF C6=1 THEN 1320
800   GOTO 990
810   A1=0
820   ! SETTING FLAG (A) IF P.V.=0
830   IF D=0 THEN A1=1
840   ! CONVERTING THE INTEREST RATE TO A DECIMAL
850   X9=B*.01
860   X7=X9+1
870   IF A=0 THEN X8=1
880   IF A=0 THEN 910
890   ! X8=1+THE DECIMAL INTEREST TO THE NTH POWER
900   X8=X7**(A*-1)
910   X1=X8*E
920   X4=1-X8
930   X=C/X9
940   IF A1=1 THEN X3=(X*-1)
950   IF A1=1 THEN 970
960   X3=X
970   X=(C/X9)*(1-X8)
980 RETURN
990   !
992   ! SECTION TO SOLVE FOR PERIODS
1000  IF A=0 THEN 1020
1010  GOTO 1090
1020  GOSUB 810
1030  X=(E-X3)/(D-X3)
1040  IF X<0 THEN X=X*(-1)
1050  IF X7<0 THEN X7=X7*(-1)
1060  A=LOG(X)/LOG(X7)
1070  ?"THE TOTAL NUMBER OF PERIODS = ";INT(A+.5)
1080  GOTO 1820
1090  ! THE SECTION TO SOLVE FOR PAYMENT
1100  IF C=0 THEN 1120
1110  GOTO 1180
1120  C=1
1130  GOSUB 810
1140  C=(1/X)*(D-X1)
1150  C=ABS(C)
1158  X=C
1159  GOSUB FUNCT
1160  ?"THE PAYMENT AMOUNT = ";FNA
1170  GOTO 1820
1180  ! SECTION TO SOLVE FOR PRESENT VALUE
1190  IF D=0 THEN 1210
1200  GOTO 1300
1210  GOSUB 810
1220  D=X+X1
1230  IF K2=1 THEN D=D**(1+B/100)
1238  X=D
1239  GOSUB FUNCT
1240  IF C9=1 THEN ?"THE PRICE OF THE BOND = ";FNA
1250  IF C9=1 THEN 1270
1258  X=D
1259  GOSUB FUNCT
1260  ?"THE PRESENT VALUE OF THIS ANNUITY = ";FNA
1270  GOTO 1820
1280  ?
1290  ?
1300  ! SECTION TO SOLVE FOR BALLOON PAYMENT
1310  ! TEST TO SEE IF ALL NECESSARY COMPONEMTS ARE THERE
1320  ! THAT ARE NECESSARY TO SOLVE FOR BALLOON PAYMENT
1330  IF C1=0 OR C4=0 OR C3=0 THEN 1850
1340  GOSUB 810
1350  E=(D-X)/X8
1360  IF K2=1 THEN E=E*(1+B/100)
1370  E=ABS(E)
1378  X=E
1379  GOSUB FUNCT
1380  IF C6=1 THEN ?"THE FUTURE VALUE OF THIS ANNUITY = ";FNA
1390  IF C6=1 THEN 1410
1398  X=E
1399  GOSUB FUNCT
1400  ?"THE BALLOON PAYMENT = ";FNA
1410  GOTO 1820
1420  ! THE SECTION TO SOLVE FOR THE INTEREST RATE"
1430  ! SETS INITIAL INTEREST TO 15%
1440  B=15/C5
1450  IF K2=1 AND D>0 THEN D=D-C
1460  IF K2=1 AND D>0 THEN A=A-1
1470  IF K2=1 AND E>0 THEN E=E+C
1480  IF K2=1 AND E>0 THEN A=A+1
1490  C8=B
1500  !
1510  ! FIND PRESENT VALUE OF ALL PAYMENTS
1520  P=(1-(1+B/100)**-A)/(B/100)*C
1530  P1=0
1540  !
1550  ! TEST TO SEE IF THERE IS A BALLOON PAYMENT
1560  IF E=0 THEN 1590
1570  ! FINDING PRESENT VALUE OF THE BALLOON PAYMENT
1580  P1=(1+B/100)**-A*E
1590  P2=P+P1
1600  !
1610  !
1620  !TEST TO SEE IF LOAN VALUE - PRESENT VALUE IS WITHIN AN 
1630  ! ACCEPTABLE RANGE
1640  IF K2=1 AND E>0 THEN D=P2-P1
1650  IF K2=1 AND E>0 THEN P2=P1
1660  IF K2<>1 AND E>0 AND C2=0 THEN D=P2-P1
1670  IF K2<>1 AND E>0 AND C2=0 THEN P2=P1
1680  IF D-P2>1 THEN 1750
1690  IF D-P2<-1 THEN 1750
1698  X=(B*C5)
1699  GOSUB FUNCT
1700  IF C9=1 THEN ?"THE YIELD TO MATURITY = ";FNA;" %"
1710  IF C9=1 THEN 1730
1718  X=(B*C5)
1719  GOSUB FUNCT
1720  ?"THE ANNUAL INTEREST = ";FNA;" %"
1730  GOTO 1820
1740  ! LOWER INTEREST RATE FOR ANOTHER ITERATION
1750  B=B-((D-P2)/D)*B
1760  !
1770  GOTO 1500
1780  ! RAISES INTEREST RATE FOR ANOTHER ITERATION
1790  !
1800  !
1810  !
1820  ?
1830  ?
1840  IF K1=3 OR K2=1 OR C2=0 THEN 2280
1850   ?"DO YOU WANT A LOAN SCHEDULE-----FOR PRINTED OUTPUT ENTER 'P'"
1852   ?"FOR OUTPUT TO TERMINAL ENTER 'T'"
1860  INPUT P$
1870   IF P$="N" OR P$="NO" THEN 2280
1872   IF P$="P" THEN OPEN#2,"CAP:",OUTPUT
1874   IF P$="P" THEN ?#2," "
1880  ?
1890  ?
1900  ?
1910  ?"ENTER FIRST AND LAST PAYMENT NUMBER"
1920  INPUT Q1,Q2
1930  ?
1938  X=C
1939  GOSUB FUNCT
1940  IF P$="T" THEN ?"THE PAYMENT AMOUNT = ";FNA
1942   IF P$="P" THEN ?#2,"THE PAYMENT AMOUNT = ";FNA
1948  X=D
1949  GOSUB FUNCT
1950  IF P$="T" THEN ?"THE PRINCIPAL AMOUNT = ";FNA
1952   IF P$="P" THEN ?#2,"THE PRINCIPAL AMOUNT = ";FNA
1958  X=(B*C5)
1959  GOSUB FUNCT
1960  IF P$="T" THEN ?"THE ANNUAL INTEREST RATE = ";FNA
1962   IF P$="P" THEN ?#2,"THE ANNUAL INTEREST RATE = ";FNA
1970  IF P$="T" THEN ?"THE TOTAL NUMBER OF PAYMENTS = ";INT(A)
1972   IF P$="P" THEN ?#2,"THE TOTAL NUMBER OF PAYMENTS = ";INT(A)
1978  X=E
1979  GOSUB FUNCT
1980  IF P$="T" THEN ?"THE BALLOON PAYMENT = ";FNA
1982   IF P$="P" THEN ?#2,"THE BALLOON PAYMENT = ";FNA
1990  IF P$="T" THEN ?
1992   IF P$="P" THEN ?#2," "
2000  IF P$="T" THEN ?
2002   IF P$="P" THEN ?#2," "
2010  IF P$="T" THEN ?"PMT #","PRINCIPAL","INTEREST","REM. BAL","TOT. INT"
2012   IF P$="P" THEN ?#2,"PMT #","PRINCIPAL","INTEREST","REM.BAL","TOT.INT"
2020  IF P$="T" THEN ?
2022   IF P$="P" THEN ?#2," "
2030  O1=C
2040  O2=O3=O5=0
2050  O4=D
2060  FOR I= 1 TO 400
2062   IF I>Q2 THEN GOTO 2302
2070  ! TESTING TO SEE IF THERE IS A BALLOON PAYMENT
2080  IF I<>A THEN 2180
2090  IF E=0 THEN 2180
2100  O1=C
2110  !O3=REM BALANCE TIMES THE INTEREST RATE
2120  O3=O4*(B/100)
2130  O2=O4
2140  O4=0
2150  O5=O5+O3
2160  A8=1.1
2170  GOTO 2230
2180  O1=C
2190  O3=O4*(B/100)
2200  O2=C-O3
2210  O4=O4-O2
2220  O5=O5+O3
2230  IF I<Q1 OR I>Q2 THEN 2270
2240  IF P$="T" THEN ?
2242   IF P$="P" THEN ?#2," "
2243  X=O2 : GOSUB FUNCT : FNA2=FNA
2245  X=O3 : GOSUB FUNCT : FNA3=FNA
2247  X=O4 : GOSUB FUNCT : FNA4=FNA
2249  X=O5 : GOSUB FUNCT : FNA5=FNA
2250  IF P$="T" THEN ? I,FNA2,FNA3,FNA4,FNA5
2252   IF P$="P" THEN ?#2,I,FNA2,FNA3,FNA4,FNA5
2254   IF P$="P" AND Q2=I THEN ?#2," "
2260  IF A8=1.1 THEN J=400
2270  NEXT I
2280  ?
2290  ?
2300  ?
2302   IF I>Q2 AND P$="P" THEN ?#2," "
2303   IF I>Q2 AND P$="P" THEN CLOSE#2
2304  IF I>Q2 AND P$="P" THEN P$=" "
2310  ?"DO YOU WISH TO MAKE ANOTHER RUN"
2320  INPUT Y$
2330  IF Y$="NO" OR Y$="N" THEN 2540
2340  ?
2350  ?
2360  GOTO 410
2370  ?"ENTER N,I,PV,FV,PMTS PER YR"
2380  INPUT G,H,I,J,C5
2390   IF C5<>0 THEN C9=G/C5
2400  FOR Z5=1 TO 2 : PRINT : NEXT Z5
2408  X=J : Y=I : Z=H
2409  GOSUB FUNCT
2410  IF G=0 THEN ?"THE NUMBER OF PERIODS = ";FNE
2418  X=J : Y=I : Z=G
2419  GOSUB FUNCT
2420  IF H=0 THEN ?"THE INTEREST RATE = ";FND
2428  X=J : Y=G : Z=H
2429  GOSUB FUNCT
2430  IF I=0 THEN ?"THE PRESENT VALUE = ";FNB
2438  X=I : Y=G : Z=H
2439  GOSUB FUNCT
2440  IF J=0 THEN ?"THE FUTURE VALUE = ";FNC
2450  GOTO 2280
2460  ?"ENTER # OF YEARS,DISCOUNT RATE,COUPON RATE,PRICE"
2470  INPUT A,B,C,D
2480  C=C/100*1000/2
2490  C5=2
2500  C9=1
2510  A=A*C5
2520  E=1000
2530  GOTO 550
2540  FOR I=1 TO 3 : PRINT : NEXT I
2550  ?"END OF PROGRAMME"
2560  FOR I=1 TO 3 : PRINT : NEXT I
2570  END
3200 INTFAC:
3201   ! THIS SUBROUTINE COMPUTES THE INTEREST FACTOR IF COMPOUNDING <> PERANN
3202   RATEA=B : COMPDD=F : PERANN=C5 : NOPMTS=A
3230   IF COMPDD=12 THEN FL12=1 ELSE FL12=0
3232   IF COMPDD=6 THEN FL22=1 ELSE FL22=0
3234   IF COMPDD=4 THEN FL13=1 ELSE FL13=0
3236   IF COMPDD=1 THEN FL15=1 ELSE FL15=0
3238   IF COMPDD=2 THEN FL14=1 ELSE FL14=0
3260   IF PERANN=12 THEN FL26=1 ELSE FL26=0
3262   IF PERANN=4 THEN FL27=1 ELSE FL27=0
3264   IF PERANN=2 THEN FL28=1 ELSE FL28=0
3266   IF PERANN=1 THEN FL29=1 ELSE FL29=0
3360   RATE=0
3362   IF RATEA=0 THEN FL33=1 ELSE FL33=0
3370   IF FL33=0 THEN RATE=RATEA/100
3380   IF FL12=1 THEN AA2=RATE/12
3390   IF FL12=1 GOTO ENDFTR
3400   IF FL13=1 THEN M=3
3402   IF FL14=1 THEN M=6
3404   IF FL15=1 THEN M=12
3406   IF FL13=1 THEN P=4
3408   IF FL14=1 THEN P=2
3410   IF FL15=1 THEN P=1
3420   AA1=0
3422   NN=0
3430   AA2=RATE/12
3440   IF P<>0 THEN RP=RATE/P
3450   RP1=RP+1
3460 LOOP1:
3470   AA3=1+AA2
3480   Y=AA3
3490   COUNT=1
3500 LOOP2:
3510   Y=Y*AA3
3520   COUNT=COUNT+1
3530   IF COUNT=M THEN FL16=1 ELSE FL16=0
3540   IF FL16=0 GOTO LOOP2
3550   IF Y>RP1 THEN FL19=1 ELSE FL19=0
3552   IF Y<RP1 THEN FL18=1 ELSE FL18=0
3554   IF Y=RP1 THEN FL17=1 ELSE FL17=0
3560   IF FL17=1 GOTO ENDFTR
3570   NN=AA2-AA1
3580   NN=NN/2
3590   IF NN>0 THEN FL21=1 ELSE FL21=0
3592   IF NN<0 THEN FL20=1 ELSE FL20=0
3594   IF NN=0 THEN FL17=1 ELSE FL17=0
3600   IF FL17=1 GOTO ENDFTR
3610   AA1=AA2
3620   IF FL18=1 AND FL20=1 THEN AA2=AA2-NN
3622   IF FL19=1 AND FL21=1 THEN AA2=AA2-NN
3630   IF FL18=1 AND FL21=1 THEN AA2=AA2+NN
3632   IF FL19=1 AND FL20=1 THEN AA2=AA2+NN
3640   GOTO LOOP1
3779 ENDFTR:
3780 EFF:
3790   EFFRAT=AA2
3792   B=EFFRAT*PERANN*100
3796 RETURN