home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
CPM
/
MISC
/
FINANCE
/
INVEST.LBR
/
CDURATN.BZS
/
CDURATN.BAS
Wrap
BASIC Source File
|
2000-06-30
|
5KB
|
95 lines
5 REM PRINT CHR$(26) -- CLEARS THE SCREEN REPLACE IF NECESSARY
10 REM BOND DURATION PROGRAM
20 REM BY BOB EDWARDS - AAII
30 REM
40 REM SEE MARCH 1984 AAII JOURNAL
50 REM
60 PRINT CHR$(26) : PRINT " BOND DURATION CALCULATIONS"
70 PRINT : PRINT "THIS PROGRAM ASSUMES SEMI-ANNUAL": PRINT "INTEREST PAYMENTS.
80 DIM D(50): DIM Q(50): DIM PC(50):I% = 0
90 PRINT : PRINT : PRINT "PROVIDE THE FOLLOWING INFORMATION:"
100 I% = I% + 1
110 PRINT : PRINT : PRINT "BOND ";I%: PRINT : PRINT : INPUT "WHAT IS THE COUPON RATE? ";C
120 PRINT : PRINT : INPUT "HOW MANY YEARS TO MATURITY? ";N: PRINT : PRINT : PRINT "WHAT IS THE BOND PRICE": INPUT "AS PERCENT OF PAR VALUE? ";F
130 PRINT : INPUT "ARE ALL VALUES CORRECT? (YES:Y, NO:N) ";J$: IF J$ = "Y" GOTO 150
140 PRINT CHR$(26) : GOTO 110
150 CD = C * 5:NP = N * 2:M = 10 * F:R = ((1000 - M) / N + 2 * CD) / ((M + 1000) / 2) / 2
160 RT = (CD - (M - 1000) * R / ((1 + R) ^ NP - 1)) / M
170 X = 100000! * RT:Z = 100000! * R:L = ABS (X - Z)
180 IF L < = .001 THEN GOTO 200
190 R = (RT + R) / 2: GOTO 160
200 Y = RT * 200:Q = 100:Y = INT (Y * Q + .5) / Q
210 PRINT CHR$(26) : PRINT "BOND ";I%: PRINT "PRICE AS % OF PAR: ";F;"%": PRINT "(PRICE FOR $1000 BOND: $";M;")": PRINT "COUPON: ";C;"%": PRINT "MATURITY: ";N;" YEARS": PRINT "YTM: ";Y;"%"
220 CM = CD / M:YR = 1 + RT
230 D = 0!
240 FOR P = 1 TO NP
250 D = D + P * CM * (1 / YR) ^ P
260 NEXT P
270 D = D + 1000 * NP / (M * (YR ^ NP))
280 P = 100:D = INT (.5 * D * P + .5) / P: PRINT : PRINT : PRINT "BOND DURATION: ";D;" YEARS":D(I%) = D
290 PRINT : PRINT : PRINT : PRINT "WHICH OF THE FOLLOWING CALCULATIONS": PRINT "DO YOU WISH TO PERFORM NEXT?": PRINT : PRINT " (S) PRICE SENSITIVITY ANALYSIS": PRINT : PRINT " (D) ANOTHER DURATION": PRINT : PRINT " (P) PORTFOLIO DURATION"
300 PRINT : PRINT " (F) CALCULATIONS FINISHED": PRINT : INPUT "(TYPE S, D, P, OR F) ";V$
310 PRINT CHR$(26) : IF V$ = "D" GOTO 100
320 PRINT CHR$(26) : IF V$ = "P" GOTO 600
330 PRINT CHR$(26) : IF V$ = "F" GOTO 910
340 PRINT CHR$(26) : PRINT " INTEREST RATE SENSITIVITY ANALYSIS"
350 PRINT : PRINT "BOND ";I%: PRINT "COUPON: ";C: PRINT "PRICE AS % OF PAR: ";F;"%"
360 M = F * 10
370 PRINT "(PRICE FOR $1000 BOND: $";M;")": PRINT "MATURITY: ";N;" YEARS": PRINT "YTM: ";Y;"%"
380 PRINT : INPUT "WHAT IS THE NEW INTEREST RATE (%)? ";X
390 PRINT "(PERCENTAGE CHANGE IS APPROXIMATE. NEW"
400 PRINT " BOND PRICE IS CALCULATED USING THE"
410 PRINT " NEW INTEREST RATE, AND IS ACCURATE.)"
420 EL = ( - D) * ((1 + X / 100) - (1 + Y / 100)) / (1 + Y / 100)
430 P = 100:EL = INT (100 * EL * P + .5) / P
440 PRINT : PRINT "THE PERCENTAGE PRICE CHANGE= ";EL;"%"
450 W = 1
460 XR = X / 200 + 1
470 M = 200 * CD / X * (1 - (XR) ^ ( - NP)) + 1000 * XR ^ ( - NP)
480 P = 100:MP = INT (M * P + .5) / P:MP = MP / 10
490 PRINT : PRINT "NEW BOND PRICE: ";MP;" PERCENT OF PAR,"
500 P = 100:MD = INT (M * P + .5) / P
510 PRINT "OR $";MD;" FOR A $1000 BOND."
520 PRINT : PRINT : PRINT "INDICATE YOUR NEXT CALCULATION:"
530 PRINT " (S) ANOTHER INTEREST RATE"
540 PRINT " (D) DURATION FOR NEXT BOND"
550 PRINT " (P) PORTFOLIO DURATION"
560 PRINT " (F) CALCULATIONS FINISHED": INPUT "(TYPE S, D, P, OR F) ";Z$
570 IF Z$ = "S" GOTO 340
580 PRINT CHR$(26) : IF Z$ = "D" GOTO 100
590 IF Z$ = "F" GOTO 910
600 FOR I = 1 TO I%: PRINT "BOND ";I,"DURATION ";D(I): NEXT I
610 GOTO 690
620 PRINT CHR$(26) :TD = 0:PT = 0
630 FOR L = 1 TO (I% - 1): PRINT "BOND ";L,"DURATION: ";D(L): INPUT " PERCENTAGE OF PORTFOLIO: ";PC(L)
640 TD = TD + D(L) * PC(L) / 100:PT = PT + PC(L): NEXT L
650 PRINT "BOND ";I%,"DURATION: ";D(I%): PRINT " PORTFOLIO PERCENTAGE: ";(100 - PT)
660 TD = TD + D(I%) * (100 - PT) / 100:W = 1000:TD = INT (TD * W + .5) / W
670 PRINT : PRINT "PORTFOLIO DURATION: ";TD;" YEARS"
680 GOTO 870
690 PRINT : PRINT
700 PRINT "THIS PROGRAM CAN CALCULATE PORTFILIO": PRINT "COMPOSITION BASED ON DOLLAR VALUES": PRINT "OR PERCENTAGES."
710 PRINT : INPUT "WHICH DO YOU PREFER? ($ OR %) ";U$
720 IF U$ = "%" THEN GOTO 620
730 TQ = 0
740 PRINT CHR$(26) : FOR L = 1 TO I%: PRINT "BOND ";L: INPUT "DOLLAR AMOUNT: $";Q(L):TQ = TQ + Q(L): NEXT L
750 FOR L = 1 TO I%
760 PC(L) = Q(L) / TQ
770 W = 10000
780 PC(L) = 100 * ( INT (PC(L) * W + .5) / W)
790 GOTO 800
800 NEXT L
810 PRINT CHR$(26) : FOR L = 1 TO I%
820 PRINT "BOND ";L; TAB( 9)"PORT %: ";PC(L); TAB( 25)"DUR: ";D(L)
830 NEXT L
840 PD = 0
850 FOR L = 1 TO I%:PD = PD + (PC(L) * D(L) / 100): NEXT L:Q = 1000:PD = INT (PD * Q + .5) / Q
860 PRINT : PRINT : PRINT "PORTFOLIO DURATION: ";PD;" YEARS"
870 PRINT : PRINT : PRINT "DO YOU WISH TO MAKE ANOTHER"
880 PRINT : PRINT "PORTFOLIO CALCULATION?"
890 PRINT : INPUT "(YES:Y, NO:N) ";E$
900 PRINT CHR$(26) : IF E$ = "Y" GOTO 600
910 PRINT:PRINT:PRINT:PRINT:PRINT:PRINT "THIS PROGRAM HAS ENDED."
920 END
E$
900 PRINT CHR$(26) : IF E$ = "Y" GOTO 600