1000 REM AAII Program No. 5 -- Realized Rate of Return 1010 REM by Robert Osterlund of AAII. (c) Copyright 1985 by 1020 REM the American Association of Individual Investors. 1030 REM From the May 1985 issue of Computerized Investing. 2000 REM initialization routine 2010 DIM MM%(100), DD%(100), YY%(100), DW(100), ND(100), TD(100) 2020 PRINT CHR$(26): REM CLEAR SCREEN 2030 PRINT "You may input up to 100 deposits or" 2040 PRINT "withdrawals. Deposits are entered as" 2050 PRINT "positive amounts, withdrawals negative." 2060 PRINT "The last entered amount, the current" 2070 PRINT "value, should also be negative." 2080 PRINT "Enter 'x' to correct the previous set" 2090 PRINT "of entries or 'f' when you are finished" 2100 PRINT "inputting data." 2110 PRINT 3000 REM data entry routine 3010 C = 0 3020 PRINT: PRINT "What is the deposit/withdrawal" 3030 PRINT "amount (e.g., -2000)"; 3040 INPUT A$ 3050 IF A$ = "x" THEN IF C > 0 THEN C = C - 1: GOTO 3020 3060 IF A$ = "f" THEN 3150 3070 IF VAL(A$) = 0 THEN 3020 3080 C = C + 1 3090 DW(C) = VAL(A$) 3100 PRINT "Made on what month, day & year" 3110 PRINT "(e.g., 4,15,1980)"; 3120 INPUT MM%(C), DD%(C), YY%(C) 3130 GOSUB 6000 3140 GOTO 3020 3150 PRINT: PRINT "What is the estimated" 3160 PRINT "rate of return (e.g., 0)"; 3170 INPUT RE 4000 REM routine to determine realized rate of return 4010 FOR J = 1 TO C 4020 TD(J) = (ND(C) - ND(J))/365 4030 NEXT J 4040 R = LOG(1+RE): K = 0 4050 NV = 0: DU = 0 4060 FOR J = 1 TO C 4070 PV = DW(J) * EXP(R*TD(J)) 4080 NV = NV + PV 4090 DU = DU + TD(J) * PV 4100 NEXT J 4110 IF ABS(DU) < .1 THEN RD = .03 * SGN(NV) * SGN(DU): GOTO 4130 4120 RD = NV / DU 4130 R = R - RD 4140 IF ABS(RD) < .00005 THEN IF DU <> 0 THEN 5000 4150 K = K + 1 4160 IF K >= 100 THEN PRINT: PRINT "Try another estimated rate.": GOTO 5160 4170 GOTO 4050 5000 REM routine to output results 5010 RR = EXP(R) - 1 5020 CLS 5030 PRINT TAB(10) "Deposit or" 5040 PRINT "Case#"; TAB(10) "Withdrawal"; TAB(25) "Date" 5050 PRINT 5060 FOR J = 1 TO C 5070 PRINT J; TAB(10) DW(J); 5075 REM YOU MIGHT HAVE TO SUBSTITUTE '1' FOR '2' IN NEXT THREE LINES 5080 PRINT TAB(25) MID$(STR$(MM%(J)),2); "/"; 5090 PRINT MID$(STR$(DD%(J)),2); "/"; 5100 PRINT MID$(STR$(YY%(J)),2) 5110 NEXT J 5120 PRINT 5130 PRINT "Estimated rate of return = "; INT(RE*10000+.5)/100; "percent." 5140 PRINT 5150 PRINT "Actual rate of return = "; INT(RR*10000+.5)/100; "percent." 5160 PRINT 5170 PRINT "Do you want to try another" 5180 PRINT "estimated rate of return (y/n)"; 5190 INPUT A$ 5200 IF A$ = "y" THEN 3150 5210 IF A$ <> "n" THEN 5170 5220 PRINT 5230 PRINT "Do you want to run this again (y/n)"; 5240 INPUT A$ 5250 IF A$ = "y" THEN PRINT CHR$(26): GOTO 3000 5260 IF A$ <> "n" THEN 5230 5270 END 6000 REM subroutine to compute the number of days from feb 28, 1700 6010 REM results are accurate from march 1, 1900 until feb 28, 2100 6020 REM adapted from the hewlett packard hp-25 applications manual 6030 MM = MM%(C): DD = DD%(C): YY = YY%(C) 6040 IF MM > 2 THEN MM = MM + 1: GOTO 6070 6050 YY = YY - 1 6060 MM = MM + 13 6070 ND(C) = INT(365.25*YY) + INT(30.6*MM) + DD - 621049 6080 RETURN