1 REM PORTFOL3:7/28/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
80 DIM ZZER$(35),ZZQ2$(ZZ1),ZZB$(ZZ1),A$(25),C$(3)
82 ZZER$="еррор - Invalid data. Resubmit it.":ZZB$="}":ZZEFLG=0:TRAP 110
83 DIM ZZBZ$(ZZ1):ZZBZ$=CHR$(253)
85 GOSUB 300
90 GOSUB 150
101 GOSUB ZZ128
103 GOTO 350
104 ? 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
114 IF ZZPEEK=136 THEN POSITION 2,22:? "филе═емпты";ZZBZ$:GOTO 2000
115 TRAP 110:? :? "еррор - A result of a calculation":? "has exceeded the maximum allowable":? "value."
117 GOSUB ZZ180:GOTO 130
120 ? :? "The СХАДЕД═ЖАЛУЕС indicate those    that must be input by the user":? :RETURN 
125 POKE 752,ZZ0:POKE 764,255:RETURN 
126 POKE 752,ZZ1:RETURN 
128 POKE 764,255:GOSUB ZZ125:RETURN 
135 SETCOLOR ZZ2,16,ZZ12:SETCOLOR ZZ4,13,ZZ6:SETCOLOR ZZ1,ZZ1,ZZ2:RETURN 
140 SETCOLOR ZZ2,Z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ZZR9-ZZ1-ZZR4:IF ZZR6>=ZZ0 THEN ZZLB=ZZLB+ZZ1
205 IF ZZLB>ZZ0 AND ABS(ZZR6)<ZZ1 THEN ZZLB=ZZLB-ZZ1:ZZR3=ZZR3*0.1
206 IF ZZLB>ZZ0 THEN FOR ZZI=ZZ1 TO ZZLB:? " ";:NEXT ZZI
207 ZZDPT=ZZR9+ZZ1:ZZLOP=ZZR2+ZZR9:IF ZZLB>ZZ0 THEN ZZLOP=ZZLOP-ZZLB:ZZDPT=ZZDPT-ZZLB
208 FOR ZZI=ZZ1 TO ZZLOP:IF ZZR6<ZZ0 AND ZZI=ZZ1 THEN ? "-";:GOTO 212
209 IF ZZI=ZZDPT THEN ? ".";
210 IF ZZLB<ZZ0 THEN ? "*";:GOTO 212
211 ZZR3=ZZR3*ZZ10:ZZINT=INT(ZZR3):ZZR3=ZZR3-ZZINT:? ZZINT;
212 NEXT ZZI:RETURN 
300 RETURN 
350 REM 
500 DIM STK$(150),P(15,3),DIV(16,10),PRI(16,10),N$(1),NO$(1),N1$(15),B1$(36)
501 ZZB$="}":IOPEN=1
502 DIM N2$(25),J$(1),KO$(4),STK1$(150),B$(10),PORTNAME$(10)
503 J$=",":POKE 752,1
504 STK$="                                                                            "
505 STK$(70)="                                                                               "
506 B$="       "
507 FOR I=1 TO 36:B1$=" ":NEXT I
509 GO TO 2000
1000 TRAP 1050
1001 OPEN #5,4,0,"D:COMDAT1"
1050 CLOSE #5
1060 TRAP 1070:OPEN #5,8,0,"D:COMDAT1":CLOSE #5:TRAP 1110:GOTO 1100
1070 CLOSE #5
1100 TRAP 1110:OPEN #6,4,0,N1$:IOPEN=1:GOTO 1111
1110 IOPEN=0:IF PEEK(195)=170 THEN IOPEN=0:CLOSE #6
1111 TRAP 110
1115 RETURN 
1200 GOSUB 1210:POSITION 1,17:? "°":POSITION 1,17:RETURN 
1210 POSITION 1,19:? "°":POSITION 1,19:RETURN 
1220 FOR IL=1 TO 3:POSITION 1,18:? "°":NEXT IL:RETURN 
2000 TRAP 110:? ZZB$:? :? "  PORTFOLIO GENERATION AND UPDATE"
2001 ? "  -------------------------------":? :? 
2003 ? "  1 - Create/destroy portfolio":? 
2005 ? "  2 - Update existing portfolio":? 
2007 ? "  3 - Perform portfolio analysis"
2008 ? :? "  4 - Exit from program"
2009 POSITION 1,17:? " OPTION (1,2,3,4)  ";:GOSUB 125:INPUT IK:GOSUB 126:GOSUB 190
2010 IF IK>4 OR IK<1 THEN GOSUB 170:GOTO 2009
2011 ON IK GOTO 2012,2012,6062,9999
2012 POSITION 1,19:IOPEN=0:? " PORTFOLIO NAME  ";:GOSUB 125:INPUT N1$:GOSUB 126
2013 IF LEN(N1$)=0 OR LEN(N1$)>10 THEN 8200
2015 FOR I=1 TO LEN(N1$):IF N1$(I,I)>"Z" OR N1$(I,I)<"A" THEN 8200
2016 NEXT I:IF LEN(N1$)=1 THEN 2018
2017 IF N1$(1,2)="D:" THEN N1$(LEN(N1$)+1,LEN(N1$)+4)=".PRT":GOTO 2070
2018 PORTNAME$=N1$:N2$="D:":N2$(3)=N1$:N1$=N2$:N1$(LEN(N1$)+1,LEN(N1$)+4)=".PRT"
2070 IF LEN(N1$)>14 THEN 8200
2075 GOSUB 126:GOSUB 1000
2080 ? "}":ON IK GOTO 2100,2400,6061
2100 GOSUB 12000:IF IOPEN=0 AND IK=1 AND DS<20 THEN POSITION 10,10:GOSUB 11000:GOTO 8100
2200 IF IOPEN=0 THEN 2206
2201 ? :? "портфолио═алреады═еьистс":? :? " 1 - Review/change portfolio":? :? " 2 - Create new portfolio":? :TRAP 10000
2202 ? " 3 - Destroy old portfolio":GOSUB 1200:? " OPTION -- ";:INPUT IK:GOSUB 126:IF IK<1 OR IK>3 THEN GOSUB 170:? "}":GOTO 2200
2203 GOSUB 12000:IF IK=2 AND DS<20 THEN POSITION 10,22:GOSUB 11000:? "}":GOTO 2200
2204 ON IK GOTO 2400,2205,7000
2205 CLOSE #6:IK=1:GOTO 2012
2206 CLOSE #6:POSITION 2,1:? "}":? "Length of holding period (months) ";:GOSUB 125:INPUT HP
2207 IF HP<1 OR HP>99 THEN GOSUB 170:GOTO 2206
2208 GOSUB 7500:GOSUB 190
2209 POSITION 2,4:? "Enter number of periods";:INPUT M:GOSUB 190:N=0:IF M<1 OR M>10 THEN GOSUB 170:GOTO 2206
2210 GOSUB 2500:? "}":? "New stock name  ";:INPUT KO$:M=INT(M):GOSUB 3200
2211 IF II=IK THEN 7100
2214 STK1$=STK$(I*4+1):STK$(I*4-3)=KO$:STK$(I*4+1)=STK1$
2215 GOSUB 126:? :? " Period      Price    Dividend":? " ------      -----    --------":GOSUB 1200
2217 POSITION 1,17:? "BEGINNING PRICE   ":GOSUB 125:INPUT A:IF A>99999 OR A<0.01 THEN GOSUB 170:GOTO 2217
2218 GOSUB 190:GOSUB 8020:IF A=0 THEN GOSUB 170:GOTO 2217
2219 PRI(I,0)=A:POSITION 6,6:? 0,A;B$
2220 FOR J=1 TO M:GOSUB 1200
2221 POSITION 1,17:? "ENTER PRICE,DIVIDEND                   ":INPUT A,B
2222 IF A>99999 OR A<0.01 OR B<0 OR B>9999 THEN GOSUB 170:GOTO 2221
2225 GOSUB 190:GOSUB 8000:IF A=0 OR B<0 THEN GOSUB 170:GOTO 2221
2226 PRI(I,J)=A:DIV(I,J)=B
2228 POSITION 6,J+6:? J,A,B:NEXT J
2230 GOSUB 3100:GOTO 4700
2250 GOSUB 1210:POSITION 1,20:? " DELETE STOCK  ";:INPUT KO$
2252 GOSUB 3200
2254 IF II=0 THEN 7200
2255 STK$(KK)=STK$(KK+4):FOR I=II TO N:PRI(I,0)=PRI(I+1,0)
2258 FOR J=1 TO M:PRI(I,J)=PRI(I+1,J):DIV(I,J)=DIV(I+1,J):NEXT J:NEXT I
2259 N=N-1:IF N=0 THEN GOSUB 8500:IK=8:GOTO 4705
2260 GOTO 4700
2300 ? ZZB$:? "CURRENT HOLDING PERIOD = ";HP;" MONTHS":? :? "    NEW HOLDING PERIOD ";:INPUT H
2310 IF H<0.1 OR H>99 THEN GOSUB 170:GOTO 2300
2315 HP=H:GOSUB 7500
2320 GOTO 4700
2400 REM 
2403 IF IOPEN=0 THEN ? "PORTFOLIO DOES NOT EXIST":GOSUB 180:GOTO 2000
2410 INPUT #6,N,M,HP:INPUT #6,STK$:FOR I=1 TO N
2411 FOR I=1 TO N:INPUT #6,A:PRI(I,0)=A:FOR J=1 TO M
2412 INPUT #6,B,C:PRI(I,J)=B:DIV(I,J)=C:NEXT J:NEXT I
2413 GOTO 4700
2500 IF IK=1 AND N>14 THEN ? "PORTFOLIO IS FULL":? ZZBZ$:FOR D=1 TO 150:NEXT D:GOTO 4700
2510 N=N+1:I=N:RETURN 
3000 ? "}":? "PORTFOLIO ";PORTNAME$:? "STOCKS IN PORTFOLIO (LIMIT IS ╠╣)":? :II=1:FOR I=1 TO N
3002 IF II<8 THEN 3004
3003 II=1:? 
3004 IK=I*4-3:IL=IK+3:? STK$(IK,IL);" ";:II=II+1:NEXT I
3005 POSITION 2,8:? "After creating or changing a":? "portfolio,save the changes on disk.":? 
3006 ? " 1- Add a new stock":? " 2- Delete an old stock entry":? " 3- Change old stock data"
3008 ? " 4- Add new data to each stock":? " 5- Change length of holding period"
3010 ? " 6- Save changes on disk"
3011 ? " 7- For print option":? " 8- To return to previous menu"
3012 GOSUB 1210
3013 POSITION 1,19:GOSUB 125:POSITION 2,20:? "OPTION  ";:INPUT IK:GOSUB 190
3020 IF IK=1 AND N>14 THEN GOTO 2500
3099 RETURN 
3100 GOSUB 3110:GOTO 3121
3110 II=I*4-3:? "}":GOSUB 126:? "  UPDATING STOCK -- ";STK$(II,II+3)
3114 ? :? "Period    Price    Dividend":? "------    -----    --------"
3115 ? 0,PRI(I,0)
3118 FOR J=1 TO M:? J,PRI(I,J),DIV(I,J)
3120 NEXT J:RETURN 
3121 GOSUB 125:POSITION 1,17:GOSUB 1200:? "ANY CHANGES (Y/N) ";:INPUT KO$
3124 IF LEN(KO$)=0 THEN RETURN 
3125 IF KO$(1,1)="Y" THEN 3128
3126 IF KO$(1,1)="N" THEN RETURN 
3127 GOSUB 170:GOTO 3121
3128 GOSUB 1200
3129 POSITION 1,17:? "PERIOD ";:INPUT J:IF J=0 THEN 3132
3130 GOSUB 190:IF J<1 OR J>M THEN GOSUB 170:GOTO 3128
3131 GOTO 3138
3132 GOSUB 1200
3133 POSITION 1,17:? "BEGINNING PRICE ":INPUT A:GOSUB 190:IF A<0.01 OR A>99999 THEN GOSUB 170:POSITION 1,17:? B1$:GOTO 3133
3134 GOSUB 8020:IF A=0 THEN GOSUB 170:GOTO 3133
3136 PRI(I,J)=A
3137 POSITION 2,5:? 0,A;B$:GOTO 3121
3138 GOSUB 1200
3139 POSITION 1,17:? "Enter price and dividend              ":INPUT A,B
3140 IF A>99999 OR A<=0 OR B>9999 OR B<0 THEN GOSUB 170:POSITION 1,18:? B1$:GOTO 3139
3142 GOSUB 8000:IF A=0 OR B<0 THEN GOSUB 170:GOTO 3139
3145 PRI(I,J)=A:DIV(I,J)=B
3150 GOTO 3100
3200 N2$=KO$:N2$(LEN(KO$)+1)="    ":KO$=N2$(1,4)
3210 FOR IK=1 TO N:KK=IK*4-3
3211 IF STK$(KK,KK+3)=KO$(1,4) THEN 3220
3213 NEXT IK:II=0:RETURN 
3220 II=IK:RETURN 
3999 RETURN 
4700 REM 
4703 GOSUB 3000
4704 IF IK<1 OR IK>8 THEN GOSUB 170:GOSUB 3013:GOTO 4705
4705 GOSUB 12000:IF DS<20 AND IK=1 OR IK=4 THEN POSITION 10,22:POKE 752,1:GOSUB 11000:GOTO 8100
4706 ON IK GOTO 2210,2250,4709,5000,2300,6000,7050,8100
4709 GOSUB 1210:? :? "STOCK SYMBOL ";:INPUT KO$:GOSUB 3200
4710 IF II=0 THEN 7200
4712 I=II
4720 GOSUB 3100
4750 GOTO 4700
5000 TRAP 110
5010 FOR I=1 TO N
5012 IF M<>10 THEN M=M+1:GOTO 5024
5022 FOR J=0 TO 9:PRI(I,J)=PRI(I,J+1):DIV(I,J)=DIV(I,J+1):NEXT J
5024 MM=M:M=M-1:GOSUB 3110:M=MM
5025 GOSUB 1200:POSITION 1,16:? "PERIOD - ";M:GOSUB 1200
5026 POSITION 1,17:? "Enter price,dividend ":GOSUB 125:INPUT B,C
5027 IF B>99999 OR B<0.01 OR C>9999 OR C<0 THEN GOSUB 170:POSITION 1,18:? B1$:GOTO 5026
5028 LET A=C:GOSUB 8000:IF A<0 OR B=0 THEN GOSUB 170:GOTO 5026
5030 PRI(I,M)=B:DIV(I,M)=A:GOSUB 3100:M=M-1:NEXT I:M=M+1:GO TO 4700
6000 CLOSE #6
6010 TRAP 6100
6011 OPEN #6,9,0,"D:COMDAT1":? #6;N;J$;M;J$;HP
6012 ? #6;STK$
6014 FOR I=1 TO N:? #6;PRI(I,0):FOR J=1 TO M
6018 ? #6;PRI(I,J);J$;DIV(I,J);J$;DIV(I,J)+PRI(I,J)-PRI(I,J-1)
6020 NEXT J:NEXT I
6030 CLOSE #6
6045 TRAP 6055:OPEN #5,8,0,N1$:CLOSE #5
6050 XIO 33,#5,0,0,N1$
6051 GOTO 6056
6055 CLOSE #5
6056 N2$="D:COMDAT1,":N2$(11)=N1$(3)
6060 TRAP 8200:XIO 32,#6,0,0,N2$
6061 CLOSE #6:STK$="                                                                            ":GOTO 2000
6062 GOSUB 9990:RUN "D:PORTFOL1":END 
6100 ? PEEK(186)+PEEK(187)*256:? "ERROR ON ";N1$;" = ";PEEK(195)
6101 END 
7000 XIO 33,#1,0,0,N1$:CLOSE #6
7001 GOTO 2000
7050 TRAP 7300:OPEN #ZZ5,ZZ8,ZZ0,"P:ZZPP":FOR ZZJJ=ZZ1 TO 320:ZZJK=PEEK(ZZDIS+ZZJJ):IF ZZJK>127 THEN ZZJK=ZZJK-ZZ128
7060 IF ZZJK>95 THEN ZZJK=ZZJK-32
7070 ? #ZZ5;CHR$(ZZJK+32);:NEXT ZZJJ:CLOSE #ZZ5:GOTO 4700
7100 POKE 752,1:POSITION 3,20:? ZZBZ$:? "еррор-Stock already exists!":FOR D=1 TO 150:NEXT D:N=N-1:GOTO 4700
7200 POKE 752,1:POSITION 3,20:? ZZBZ$:? "еррор-Stock does not exist!":FOR D=1 TO 150:NEXT D:GOTO 4700
7300 POKE 752,1:? ZZBZ$:POSITION 2,22:? "дежице═еррор║":FOR D=1 TO 150:NEXT D:CLOSE #5:GOTO 4700
7500 HP=(INT(HP*10)/10):RETURN 
8000 REM 2 SIGN.DIGIT DEC.LIMITER
8005 ZZ13=B
8010 ZZ13=(INT(ZZ13*100)/100)
8015 B=ZZ13
8020 ZZ13=A:ZZ13=(INT(ZZ13*100)/100)
8025 A=ZZ13:ZZ13=13:RETURN 
8100 CLOSE #6:GOTO 503
8200 ? ZZBZ$:POKE 752,1:POSITION 2,21:? "филе═наме═еррор║":FOR D=1 TO 150:NEXT D:GOTO 503
8500 ? "}":? "        портфолио═дестроыед";ZZBZ$:? :? 
8505 POKE 752,1:? " You have deleted the last stock in":? "portfolio ";PORTNAME$;". You may create"
8506 ? "another portfolio if you wish."
8509 TRAP 8600
8510 XIO 33,#1,0,0,N1$:CLOSE #6
8515 TRAP 40000
8516 FOR D=1 TO 300:NEXT D
8520 RETURN 
8600 GOTO 8515
9990 GOSUB 150:? ZZB$:GOSUB 126:POSITION 7,22:? "═лоадинг═тхе═неьт═сецтион═":RETURN 
9999 TRAP 40000:TRAP 9999:? "}":POSITION 10,10:? "═ретурнинг═то═мену═":RUN "D:MENU"
10000 TRAP 40000:GOSUB 170:? "}":GOTO 2200
11000 ? "Щ═дискетте═фулл═":FOR D=0 TO 300:NEXT D:TRAP 40000:RETURN 
12000 OPEN #2,6,0,"D:*.*"
12002 INPUT #2;A$:IF A$(2,2)=" " THEN 12002
12004 CLOSE #2:C$=A$(1,3):DS=VAL(C$)
12005 RETURN 
