rem *--------------- Section 4.0 ------------------*
rem *						   *
rem *      HISTORICAL STOCK STATISTICAL SUMMARY    *
rem *	   ------------------------------------    *
rem *	COPYRIGHT: E. A. Valenzuela		   *
rem *	DATE:      February 5, 1983		   *
rem *	VERSION:   1.31				   *
rem *----------------------------------------------*

rem --- requires subroutines ---
rem        scrnin.bas
rem        qksort%.bas ... for sorting integers
rem        qksort$.bas ... for sorting alphabetically
rem        stkfprnt.bas    for printing
rem        stkprice.bas    for jump vectors

rem ...... check for end of file       ......

7000 if end # 9 then 7199

print clear$; fn.down$(3); fn.right$(10); \
      "READING IN STOCK FILE"

open "b:stkfil01.dat" recl 80 as 9 buff 8 recs 128

nstk% = 0
7050 nstk%=nstk%+1
    i%=nstk%

    GOSUB 310

    if nshrs%(i%)=0 then equiv(i%)=0 else \
       equiv(i%)=totpurprice(i%)/nshrs%(i%)
    day%(i%) =fn.juldate%(purdate$(i%))
goto 7050

7199 REM "reached end-of-file on unit 9: # of stocks is ";i%
close 9
nstk% = nstk%-1

if end # 8 then 7399

  print fn.line$(6); fn.right$(10); "READING IN CURRENT PRICES"

open "b:stkprice.dat" as 8

GOSUB 320
  date1% = fn.juldate%(newdate$)
GOSUB 330

for i%=1 to nstk%
  NEWvalue(i%) = float(nshrs%(i%)) * NEWprice(i%)
  INCVALUE(i%) = NEWvalue(i%) - totpurprice(i%)
  if totpurprice(i%)=0 then pcntinc(i%)=0 else \
     pcntinc(i%)  = INCVALUE(i%)/totpurprice(i%) * 100.
  if NEWprice(i%)=0 then yield(i%)=0 else \
     YIELD(I%)    = DIVIDEND(I%) / NEWPRICE(I%) * 100.
  if totpurprice(i%)=0 then anyield(i%)=0 else \
     anyield(i%)  = NEWvalue(i%) / totpurprice(i%)
next i%

 print fn.line$(8); fn.right$(10); "CALCULATING ANNUAL YIELD"

for i%=1 to nstk%
    date0% = day%(i%)
    years = float(date1% - date0%)*0.00274
rem ... 0.00274 is 1/365 ...
  anyield(i%) = ((anyield(i%))^(1./years) - 1.)*100.
  anyield(i%) = anyield(i%) + yield(i%)
rem ... revise for extremes ...
  if anyield(i%) > 999 then anyield(i%) = 999.
  if anyield(i%) < -99 then anyield(i%) = -99.
next i%

goto 7400

7399 print "end-of-file on unit 8 reached"

7400 close 8

7600 print clear$; fn.down$(1); fn.right$(5); \
    "HISTORICAL PERFORMANCE SUMMARY OPTION LIST"

print fn.down$(2); fn.right$(10); "SORTING OPTIONS:"; down$
print tab(5);"0 = return to main menu"
print tab(5);"1 = on date purchased"
print tab(5);"2 = by number of shares"
print tab(5);"3 = by stock exchange"
print tab(5);"4 = by purchase cost"
print tab(5);"5 = by current value"
print tab(5);"6 = by percentage increase in value"
print tab(5);"7 = by annual yield"
print tab(5);"8 = by $ increase in value"
print tab(5);"9 = alphabetical by stock name"
print tab(4);"10 = by dividend yield"

print down$; fn.right$(10); bell$;
  input "enter option number for sort:"; option%
if option%=0 then goto 900
on option% goto 7610,7620,7630,7640,7650,7660,7670,7680,7690,7695

7610 sort$ = "date of purchase"
    for j%=1 to nstk%
      X%(j%) = day%(j%)
    next j%
    goto 7700

7620 sort$ = "number of shares"
    for j% = 1 to nstk%
      X%(j%) = nshrs%(j%)
    next j%
    goto 7700

7630 sort$ = "stock exchange"
     EXCH$ = "NYSE"
     kount% = 0
     i% = 1
7631 kount% = kount% + 1
    for j%=1 to nstk%
      if( xchng$(j%) = EXCH$ ) then kode%(i%) = j% : i%=i%+1
    next j%

      if( kount% = 1 ) then EXCH$ = "AMEX" : goto 7631
      if( kount% = 2 ) then EXCH$ = "OTC"  : GOTO 7631
      if( kount% = 3 ) then EXCH$ = "OTHER": goto 7631
 
    n%=nstk%
    sortcheck$="yes"
    goto 7710

7640 sort$ = "total purchase price"
    for j%=1 to nstk%
      X%(j%) = int%( totpurprice(j%) )
    next j%
    goto 7700

7650 sort$ = "current value"
    for j%=1 to nstk%
      X%(j%) = int%( NEWvalue(j%) )
    next j%
    goto 7700

7660 sort$ = "percentage increase in value"
    for j%=1 to nstk%
      X%(j%) = int%( pcntinc(j%)*10. )
    next j%
    goto 7700

7670 sort$ = "annual yield (including dividends)"
    for j%=1 to nstk%
      X%(j%) = int%( anyield(j%)*10. )
    next j%
    goto 7700

7680 sort$ = "dollar increase in value"
    for j%=1 to nstk%
      X%(j%) = int%( incvalue(j%)*10. )
    next j%
    goto 7700

7690 SORT$ = "ALPHABETICAL BY NAME"
    sortcheck$ = "no"
    GOTO 7710

7695 sort$ = "annual dividend yield"
    for j%=1 to nstk%
      X%(j%) = int%( yield(j%)*10. )
    next j%
    goto 7700
      
rem ..... sort the percentage increases .....

7700 sortcheck$ = "yes"
    N% = NSTK%
    FOR J%=1 TO N%
      KODE%(J%)=J%
   NEXT J%

gosub 1500
goto 7710

7705 gosub 1550

7710 rem ...... print out statistical summary by calling print subroutine ...

title$ = "OPTION 4 - HISTORICAL SUMMARY OF STOCK PORTFOLIO"
TITLE2$ = "SORTED BY " + SORT$
 
gosub 6600
gosub 6620

goto 7600

7499 return
rem ----------------end of statistical summary--------------------------
rem                        SUBROUTINE