1 REM PORTFOL1:7/22/80:REL. 1.1
10 REM "COPYRIGHT  CONTROL  DATA  1980"
31 ZZ0=0:ZZ1=1:ZZ2=2:ZZ3=3:ZZ4=4:ZZ5=5:ZZ6=6:ZZ10=10:ZZ14=14:ZZ21=21:ZZ125=125:ZZ126=126:ZZ180=180:ZZ200=200
32 ZZ7=7:ZZ8=8:ZZ9=9:ZZ12=12:ZZ20=20:ZZ22=22:ZZ128=128:ZZ150=150:ZZ170=170:ZZ190=190:ZZ23=23:ZZ764=764:ZZFF=255
33 ZZDIS=PEEK(106)*256-961
34 ZZ13=13:ZZ100=100:ZZ36=36:ZZ11=11
35 DIM B$(34):FOR I=1 TO 34:B$(I)=" ":NEXT I
80 DIM ZZER$(35),ZZQ2$(ZZ1),ZZB$(ZZ1)
82 ZZER$="ÅÒÒÏÒ - Invalid data. Resubmit it.":ZZB$="}":ZZEFLG=0:TRAP 110
83 DIM ZZBZ$(ZZ1):ZZBZ$=CHR$(253)
85 GOSUB 300
100 GOSUB 140:? ZZB$:? "Type Æ to create, examine, or":? "       alter FILES":? 
102 ? "     É for INFORMATION about the":? "       program"
103 ? :? "     Ó for a SAMPLE run":? :? "     ÒÅÔÕÒÎ for portfolio analysis"
104 GOSUB ZZ128
105 INPUT ZZQ2$:IF ZZQ2$="I" THEN GOSUB 9990:RUN "D:PORTFOL2"
106 IF ZZQ2$="S" THEN ? ZZB$:GOSUB 145:GOTO 350
107 IF ZZQ2$="F" THEN GOSUB 9990:RUN "D:PORTFOL3"
108 ? ZZB$:GOSUB ZZ150:GOTO 400
110 ZZGOTO=256*PEEK(187)+PEEK(186):ZZPEEK=PEEK(195):IF ZZPEEK=ZZ8 OR ZZPEEK=18 THEN GOSUB 170:TRAP 110:GOTO ZZGOTO
111 IF ZZPEEK<>ZZ3 AND ZZPEEK<>7 AND ZZPEEK<>11 THEN GOTO ZZGOTO
115 TRAP 110:? :? "ÅÒÒÏÒ - A result of a calculation":? "has exceeded the maximum allowable":? "value."
116 GOSUB ZZ180:GOTO 130
120 ? :? "The óèáäåä öáìõåó indicate those    that must be input by the user.":? :RETURN 
125 POKE 752,ZZ0:RETURN 
126 POKE 752,ZZ1:RETURN 
128 POKE 764,255:GOSUB ZZ125:RETURN 
130 GOSUB 135:? ZZB$:? :? "End of problem"
131 ? :? "Type Ù to run another problem":? :? "     ÒÅÔÕÒÎ to exit to menu":? :GOSUB ZZ128:INPUT ZZQ2$
132 IF ZZQ2$<>"Y" THEN PRINT "}":TRAP 40000:POKE 752,1:POSITION 10,10:? " ÒÅÔÕÒÎÉÎÇ ÔÏ ÍÅÎÕ ":RUN "D:MENU"
133 RESTORE :GOTO 100
135 SETCOLOR ZZ2,16,ZZ12:SETCOLOR ZZ4,13,ZZ6:SETCOLOR ZZ1,ZZ1,ZZ2:RETURN 
140 SETCOLOR ZZ2,ZZ13,ZZ2:SETCOLOR ZZ4,ZZ14,ZZ2:SETCOLOR ZZ1,ZZ0,ZZ12:RETURN 
145 SETCOLOR ZZ2,ZZ14,ZZ0:SETCOLOR ZZ4,ZZ14,ZZ8:SETCOLOR ZZ1,ZZ1,ZZ12:RETURN 
150 SETCOLOR ZZ2,ZZ9,ZZ2:SETCOLOR ZZ4,ZZ5,ZZ4:SETCOLOR ZZ1,ZZ0,ZZ12:RETURN 
155 SETCOLOR ZZ2,ZZ14,ZZ10:SETCOLOR ZZ4,ZZ14,ZZ0:SETCOLOR ZZ1,ZZ1,ZZ0:RETURN 
170 POSITION ZZ3,ZZ21:? ZZER$:ZZEFLG=ZZ1:? ZZBZ$:RETURN 
180 POSITION ZZ2,ZZ23:GOSUB ZZ128:? "Type Ð to print, ÒÅÔÕÒÎ to continue";
181 OPEN #ZZ7,ZZ4,ZZ0,"K:ZZKK":GET #ZZ7,ZZDATA:CLOSE #ZZ7
182 IF ZZDATA=80 THEN TRAP 189:OPEN #ZZ5,ZZ8,ZZ0,"P:ZZPP":GOTO 186
183 IF ZZDATA<>155 THEN 180
184 GOSUB ZZ126:? ZZB$:RETURN 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L(MAXSTK),M(MAXSTK),N(MAXSTK),B(MAXSTK),Z(ZZ5)
304 DIM P(MAXSTK,ZZ11),A(MAXSTK,ZZ2),W(MAXSTK,ZZ2)
320 FOR I=ZZ0 TO MAXSTK:FOR J=ZZ0 TO ZZ11:P(I,J)=ZZ0:NEXT J:NEXT I
349 RETURN 
350 RESTORE :GOSUB 5000:READ N1$,N3,N4,N9,N6,N7,N3$,N5:? " ÂÁÃË":N1$="D:BACK":GOSUB 6000
351 POSITION ZZ3,ZZ4:? "Holding period   (months) ";N3
352 POSITION ZZ3,ZZ6:? "Number of stocks          ";N4
353 POSITION ZZ3,ZZ8:GOSUB 4000:? "±"
354 POSITION ZZ3,5:? "Number of periods         ";N6
356 POSITION ZZ3,16:? "Do you want indexes"
358 POSITION ZZ3,17:? "of portfolio value?     Ù":GOSUB ZZ180
371 N7=1
380 FOR I=ZZ1 TO N4:W(I,ZZ1)=I:W(I,ZZ2)=ZZ1/N4:NEXT I:GO TO 580
398 DATA D:BACK,4,5,1,9,1,YES,2
400 N1$="          ":GOSUB 5000:INPUT N1$:IF LEN(N1$)=0 THEN 7006
401 FOR I=1 TO LEN(N1$):IF N1$(I,I)>"Z" OR N1$(I,I)<"A" THEN 7006
403 NEXT I:GOSUB ZZ190:N1$(LEN(N1$)+1,LEN(N1$)+4)=".PRT":GOSUB 6000:POSITION ZZ3,ZZ4:? "Holding period   (months)    ";N3
404 POSITION ZZ3,ZZ6:? "Number of stocks             ";N4
405 POSITION ZZ3,5:? "Number of periods            ";N6
406 IF N4<=MAXSTK THEN 408
407 POSITION ZZ3,ZZ21:? ZZBZ$:? "Stock # must be less then ";MAXSTK:GOTO 100
408 POSITION ZZ3,ZZ8:GOSUB 4000:INPUT N9:GOSUB ZZ190:IF N9<1 OR N9>2 THEN GOSUB 170:GOTO 408
409 N7=1
410 GOSUB ZZ180:POSITION ZZ3,ZZ4:? "Do you want indexes"
411 POSITION ZZ3,ZZ6:? "of portfolio value? (Y/N) ";:INPUT N3$
412 IF LEN(N3$)=0 THEN N3$=" "
413 N3$=N3$(1,1):IF N3$="Y" OR N3$="N" THEN 415
414 GOSUB 170:GOTO 411
415 GOSUB 190:GOTO 540
450 GOSUB 9990:RUN "D:PORTFOL3"
540 GOSUB ZZ180
580 IF ZZQ2$="S" THEN 890
590 ON N9 GOTO 640,610
610 GOSUB 3600:K=0
615 FOR I=ZZ1 TO N4:K=K+ZZ1:IF K>ZZ10 THEN K=ZZ1:GOSUB ZZ180:GOSUB 3600
618 GOSUB 125:POSITION ZZ2,ZZ7+K:? "STOCK # ";I;"  ";N1$(I*4-3,I*4);:INPUT W2:IF W2>1 OR W2<0 THEN 7100
619 LET X=W2+X:LET W1=I:GOTO 7075
621 GOSUB 190:W(I,ZZ1)=W1:W(I,ZZ2)=W2
622 GOSUB 126
625 NEXT I:GOTO 800
640 REM 
700 FOR I=ZZ1 TO N4:W(I,ZZ1)=I:W(I,ZZ2)=ZZ1/N4:NEXT I:GO TO 890
800 IF X>1 THEN 7200
890 POSITION ZZ4,ZZ14:? "Ðìåáóå ÷áéô æïò ôèå ãáìãõìáôéïîó":Q=ZZ1
900 FOR J=1 TO N4-1:FOR I=1 TO N4-1
910 IF W(I+1,1)>W(I,1) THEN 950
920 PP=W(I,1):QQ=W(I,2)
930 W(I,1)=W(I+1,1):W(I,2)=W(I+1,2)
940 W(I+1,1)=PP:W(I+1,2)=QQ
950 NEXT I:NEXT J
980 REM 
985 N0=N6+ZZ1
991 FOR N=ZZ0 TO ZZ11:R(N)=ZZ0:H(N)=ZZ0:NEXT N
1010 H(ZZ1)=ZZ100:R(ZZ1)=ZZ100
1020 FOR I=ZZ1 TO N4:A(I,ZZ1)=ZZ100:NEXT I
1050 FOR J=ZZ2 TO N6+ZZ1:B=ZZ0
1100 FOR I=ZZ1 TO N4:A(I,ZZ2)=A(I,ZZ1)*(ZZ1+P(I,J+N7-ZZ2)):NEXT I
1150 FOR I=ZZ1 TO N4:H(J)=H(J)+A(I,ZZ2)
1190 B=B+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";:ZZR1=W1:GOSUB ZZ200:GO TO 1750
1730 ? :? "Stocks ";N5+1;" to ";N5+N4:ZZR9=ZZ4:ZZR8=ZZ3:? 
1740 ? "Mean weight for each stock =";:ZZR1=X/N4:GOSUB ZZ200:? 
1750 ? :IF N3$<>"Y" THEN 1850
1780 GOSUB ZZ180:? "   Indexes of portfolio value":? :? "                    Constant"
1781 ? "Period   Buy/Hold   Proportions":? 
1820 FOR I=ZZ1 TO N6+ZZ1:ZZR9=ZZ3:ZZR8=-ZZ1:ZZR1=I+N7-ZZ2:GOSUB ZZ200:ZZR9=ZZ5:ZZR8=ZZ3
1822 ? "     ";:ZZR1=H(I):GOSUB ZZ200
1830 ? "    ";:ZZR1=R(I):GOSUB ZZ200:? :NEXT I
1850 ZZR9=ZZ2:ZZR8=ZZ4:? 
1853 GOSUB ZZ180:SETCOLOR ZZ2,ZZ10,ZZ4
1857 ? :? "                       Constant"
1860 ? "             Buy/Hold  Proportions"
1870 ? :? "Mean          ";:ZZR1=M1:GOSUB ZZ200:? "    ";:ZZR1=M2:GOSUB ZZ200:? 
1880 ? "S.D.          ";:ZZR1=D1:GOSUB ZZ200:? "    ";:ZZR1=D2:GOSUB ZZ200:? 
1910 ? "Mean of logs  ";:ZZR1=M3:GOSUB ZZ200:? "    ";:ZZR1=M4:GOSUB ZZ200:? 
1920 ? "S.D.          ";:ZZR1=D3:GOSUB ZZ200:? "    ";:ZZR1=D4:GOSUB ZZ200:? 
1930 ? "Geom. mean    ";:ZZR1=G1:GOSUB ZZ200:? "    ";:ZZR1=G2:GOSUB ZZ200:? 
1950 IF N3=ZZ12 THEN 1982
1951 ? :? "Annualized":? "arithmetic":? "mean return   ";
1952 ZZR1=A1:GOSUB ZZ200:? "    ";:ZZR1=A2:GOSUB ZZ200:? :? 
1970 ? :? "Annualized":? "geometric":? "mean return   ";
1980 ZZR1=A3:GOSUB ZZ200:? "    ";:ZZR1=A4:GOSUB ZZ200:? :? 
1982 GOSUB ZZ180:SETCOLOR ZZ2,ZZ6,ZZ5
2050 POSITION 1,1:? :? "Do you want average figures":? 
2070 ? "(average return--variance of":? 
2090 ? "single stock portfolios) for":? 
2110 ? "comparison purposes? (Y/N) ";:IF ZZQ2$="S" THEN ? "Ù"
2111 IF ZZQ2$="S" THEN GOSUB ZZ128:N3$="Y":GOTO 2116
2112 GOSUB ZZ128:INPUT N3$
2116 IF LEN(N3$)=0 THEN N3$=" "
2117 N3$=N3$(1,1):IF N3$="Y" OR N3$="N" THEN 2119
2118 GOSUB 170:GOTO 2050
2119 GOSUB 190
2131 IF N3$<>"Y" THEN 130
2300 GOSUB ZZ126:POSITION ZZ4,ZZ14:? "Ðìåáóå ÷áéô æïò ôèå ãáìãõìáôéïîó"
2310 FOR X=ZZ0 TO MAXSTK:I(X)=ZZ0:J(X)=ZZ0:K(X)=ZZ0:L(X)=ZZ0:F(X)=ZZ0:G(X)=ZZ0:M(X)=ZZ0:N(X)=ZZ0:NEXT X
2480 FOR I=ZZ1 TO N4:FOR J=N7 TO N6+N7-ZZ1
2560 I(I)=I(I)+P(I,J):J(I)=J(I)+LOG(ZZ1+P(I,J))
2570 K(I)=K(I)+(P(I,J))^ZZ2
2571 L(I)=L(I)+(LOG(ZZ1+P(I,J)))^ZZ2:NEXT J
2590 F(I)=I(I)/N6:G(I)=J(I)/N6
2610 M(I)=SQR((N6*K(I)-I(I)*I(I))/(N6^ZZ2))
2620 N(I)=SQR((N6*L(I)-J(I)*J(I))/(N6^ZZ2)):NEXT I:M5=ZZ0:M6=ZZ0:S5=ZZ0:S6=ZZ0
2660 FOR I=ZZ1 TO N4:M5=F(I)+M5:M6=G(I)+M6:S5=S5+M(I):S6=S6+N(I):NEXT I
2710 M5=M5/N4:M6=M6/N4:S5=S5/N4:S6=S6/N4:A5=(ZZ1+M5)^(ZZ1/N3)-ZZ1:G5=EXP(M6)-ZZ1:G6=EXP(M6/N3)-ZZ1:? :? 
2720 GOSUB ZZ180:SETCOLOR ZZ2,ZZ9,ZZ2
2800 ? "Single stock performance average":? 
2801 ZZR9=4
2810 ? :? "Mean        ",:ZZR1=M5:GOSUB ZZ200:? :? "S.D.        ",:ZZR1=S5:GOSUB ZZ200:? 
2830 ? "Mean of logs",:ZZR1=M6:GOSUB ZZ200:? :? "S.D. of logs",:ZZR1=S6:GOSUB ZZ200:? 
2840 ? "Geometric mean  ",:ZZR1=G5:GOSUB ZZ200:? 
2860 IF N3=ZZ12 THEN 2880
2861 ? :? :? "Annualized mean":? "returns:":? :? "Arithmetic mean ",:ZZR1=A5:GOSUB ZZ200:? 
2870 ? :? "Geometric mean",:ZZR1=G6:GOSUB ZZ200
2880 ? :? :GOSUB ZZ180:GO TO 130
3000 IF N6>ZZ10 THEN POSITION ZZ3,ZZ21:? "This number must less than 11":GO TO 407
3003 GO TO 408
3035 IF N7>ZZ10-N6+ZZ1 THEN POSITION ZZ3,ZZ21:? "This number must less than ";ZZ10-N6+ZZ2:GO TO 408
3040 GO TO 409
3600 ? ZZB$:? :? :? "Enter weight for each stock:"
3620 ? :RETURN 
4000 ? "Stock selection options:"
4002 ? "   1. All stocks, equal weights"
4003 ? "   2. All stocks, specified weights":? 
4004 RETURN 
5000 POSITION ZZ3,ZZ1:? "Name of portfolio: ";:RETURN 
6000 IF LEN(N1$)=0 THEN ZZPEEK=170:GOTO 7001
6001 TRAP 7000
6002 IF LEN(N1$)=1 THEN N3$="D:":N3$(3)=N1$:N1$=N3$
6003 IF N1$(1,2)<>"D:" THEN N3$="D:":N3$(3)=N1$:N1$=N3$
6007 CLOSE #6
6008 TRAP 7000:OPEN #6,4,0,N1$
6009 TRAP 110:POSITION 2,22:? "œ":POSITION 1,5
6010 INPUT #6,N4,N6,N3
6020 INPUT #6,N1$
6030 FOR I=1 TO N4:INPUT #6,K
6040 FOR J=1 TO N6:INPUT #6,M5,M6,K
6041 XXP0=M5+M6-K
6042 P(I,J)=M6+(M5-XXP0)/XXP0:NEXT J:NEXT I
6045 CLOSE #6
6050 RETURN 
7000 ZZPEEK=PEEK(195):POKE 752,1
7001 IF ZZPEEK=167 THEN POSITION 2,22:? "ÆÉÌÅ ÌÏÃËÅÄ":? ZZBZ$:GOTO 7003
7002 POSITION 2,22:? " ÆÉÌÅ ÎÏÔ ÆÏÕÎÄ ";:? ZZBZ$
7003 FOR D=1 TO 150:NEXT D:CLOSE #6:GOTO 100
7006 POKE 752,1:? ZZBZ$:POSITION 2,22:? "ÉÌÌÅÇÁÌ ÆÉÌÅ ÎÁÍÅ ":FOR D=1 TO 100:NEXT D:GOTO 100
7075 ZZ13=W2:GOSUB 8000:W2=ZZ13:ZZ13=13
7076 IF W1<1 THEN GOSUB 170:GOTO 618
7080 IF W2<0 THEN GOSUB 170:GOTO 618
7081 GOTO 621
7100 POKE 752,1:? ZZBZ$:POSITION 3,20:? "ÅÒÒÏÒ-Please enter a valid weight!":FOR D=1 TO 150:NEXT D
7110 POSITION 3,20:? B$:GOTO 618
7200 POKE 752,1:? ZZBZ$:POSITION 1,20:? "ÅÒÒÏÒ-Stock weights are greater than 1.":FOR D=1 TO 150:NEXT D
7210 POSITION 1,20:? B$:X=0:GOTO 610
8000 LET ZZ13=INT(ZZ13*100)/100:RETURN 
9990 GOSUB 135:? ZZB$:GOSUB 126:POSITION 7,22:? " ÌÏÁÄÉÎÇ ÔÈÅ ÎÅØÔ ÓÅÃÔÉÏÎ ":RETURN 
