rem *--------------- Section 8.0 ------------------*
rem *						   *
rem *   HISTORICAL PORTFOLIO 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

8000 rem ...... check for end of file       ......
 
n%=50
dim namstk$(n%),nr%(n%),a(n%),b(n%),sa(n%),sb(n%),see(n%),r2(n%),r(n%), \
  ygavg(n%),yavg(n%),ysd(n%),min(n%),max(n%),yield(n%),ratio(n%),ab(n%)
dim x%(N%), kode%(N%) 
if end # 10 then 8099

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

open "B:STKPRICE.DAT" as 8
 read #8; nstk%, newdate$, olddate$
close 8

open "B:BETA.DAT" AS 10
 nitems% = nstk% + 2	: rem ... read S&P 500 and portfolio
 nstk% = nstk% + 1
  for i% = 1 to nitems%
    read #10; k%,namstk$(i%),nr%(i%),a(i%),b(i%),sa(i%),sb(i%),see(i%), \
     r2(i%),r(i%),ygavg(i%),yavg(i%),ysd(i%),min(i%),max(i%),yield(i%), \
     ratio(i%),ab(i%)
  next i%
CLOSE 10
  goto 8050
        
8099 REM "reached end-of-file on unit 10: # of stocks is "; i%
close 10

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

print fn.down$(2); fn.right$(10); "SORTING OPTIONS:"; down$
print tab(5);"0 = return to main menu"
print
print tab(5);"1 = on total risk/return ratio"
print tab(5);"2 = on alpha/beta ratio"
print tab(5);"3 = by alpha"
print tab(5);"4 = by beta"
print tab(5);"5 = by geometric average return"
print tab(5);"6 = by standard deviation"

print down$; fn.right$(10); bell$;
  input "enter option number for sort:"; option%
if option%=0 then RETURN
on option% goto 8010,8020,8025,8030,8040,8045

8010 sort$ = "total risk/return ratio"
    for j%=1 to nitems%
      X%(j%) = ratio(j%)*100.
    next j%
    goto 8017

8020 sort$ = "alpha/beta ratio"
    for j% = 1 to nitems%
      X%(j%) = ab(j%)*1000.
    next j%
    goto 8017

8025 sort$ = "alpha - return variable"
    for j% = 1 to nitems%
      X%(j%) = a(j%)*10000.
    next j%
    goto 8017

8030 sort$ = "beta value"
    for j%=1 to nitems%
      X%(j%) = b(j%)*100.
    next j%
    goto 8017

8040 sort$ = "geometric average return"
    for j%=1 to nitems%
      X%(j%) = ygavg(j%)*10000.
    next j%
    goto 8017

8045 sort$ = "standard deviation of returns"
    for j%=1 to nitems%
      X%(j%) = ysd(j%)*10000.
    next j%
    goto 8017

rem ..... sort the percentage increases .....

8017 sortcheck$ = "yes"
    N% = NITEMS%
    FOR J%=1 TO N%
      KODE%(J%)=J%
   NEXT J%

gosub 1500

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

filename$ = "B:BETA.DAT"
title1$ = "HISTORICAL SUMMARY OF PORTFOLIO from: "
TITLE2$ = "SORTED BY " + SORT$ + "      DATE: "
 
for9$=" ## /........../ ###  ##.###  ##.###  #.###  #.###  #.###  #.###  #.##"\
 +"#  ##.###  ##.###  ##.### ##.### ##.### ##.###  ###.##  ###.##"  
for8$=" ## /......../ #####  ##.###  ##.###  #.###  #.###  #.###  #.### ##.##"\
 +"#  ##.###  ##.###  ##.### ##.### ##.### ##.###  ###.##  ###.##"  

gosub 9023
 for i%=1 to nitems%
  j% = kode%(i%) 
if j% < nitems% then \
print using for9$; i%,namstk$(j%),nr%(j%),a(j%),b(j%),sa(j%),sb(j%), \
  see(j%),r2(j%),r(j%),ygavg(j%),yavg(j%),ysd(j%),min(j%),max(j%),   \
  yield(j%),ratio(j%),ab(j%) \
else \
print using for8$; j%,namstk$(j%),nr%(j%),a(j%),b(j%),sa(j%),sb(j%), \
  see(j%),r2(j%),r(j%),ygavg(j%),yavg(j%),ysd(j%),min(j%),max(j%),   \
  yield(j%),ratio(j%),ab(j%)
  if fn.mod%(i%,5) eq 5 then print
 NEXT I%
 
CONSOLE
goto 8050

8049 return
rem ---------- END OF PORTFOLIO STATISTICS --------
