/* Stock Market Analysis Using the SAS System: */ /* Portfolio Selection and Evaluation */ /* Chapter Number and Page Number of Example Code */ /* Listed in Comments Preceeding Example Code */ /* Page Numbers Listed for Data Sets Created in Previous Examples */ /* Chapter 1 */ /* Example Code Found on Page 4 */ data sp1; input year v d @@; label v='End-of-Year Index Value' d='Dividends'; cards; 1970 92.15 3.14 1971 102.09 3.07 1972 118.05 3.15 1973 97.55 3.38 1974 68.56 3.60 1975 90.19 3.68 1976 107.46 4.05 1977 95.10 4.67 1978 96.11 5.07 1979 107.94 5.70 1980 135.76 6.16 1981 122.55 6.63 1982 140.64 6.87 1983 164.93 7.09 1984 167.24 7.53 1985 211.28 7.90 1986 242.17 8.28 1987 247.08 8.81 1988 277.72 9.73 1989 353.40 11.05 ; /* Example Code Found on Page 5 */ /* SP1 Data Set Created in Example Code on Page 4 */ proc print data=sp1(obs=5) label; var year v d; title 'Background Topics'; title2 'Printing the SP1 Data Set'; title3 'First Five Observations'; run; /* Example Code Found on Page 6 */ /* SP1 Data Set Created in Example Code on Page 4 */ proc plot data=sp1 vpct=150; plot v*year; plot d*year; title2 'Plotting Data Values versus Year'; title3; run; /* Example Code Found on Page 7 */ /* SP1 Data Set Created in Example Code on Page 4 */ data sp2; set sp1; v_1=lag(v); r=(v-v_1+d)/v_1; r_per=r*100; label v_1='Lagged Index Value' r='Returns' r_per='Percentage Returns'; run; proc print data=sp2 label; var year v v_1 d r r_per; title2 'Printing the Single Period Returns'; run; /* Example Code Found on Page 8 */ /* SP2 Data Set Created in Example Code on Page 7 */ proc plot data=sp2 vpct=150; plot r*year / vref=0; title2 'Plotting Returns versus Year'; run; /* Example Code Found on Page 11 */ /* SP2 Data Set Created in Example Code on Page 7 */ data sp3; set sp2; where year ge 1985; run; proc transpose data=sp3 out=sp4; var r; run; proc print data=sp4; title2 'Printing the SP4 Data Set'; run; /* Example Code Found on Page 12 */ /* SP4 Data Set Created in Example Code on Page 11 */ data sp5; set sp4; t=5; c1=col1+1; c2=col2+1; c3=col3+1; c4=col4+1; c5=col5+1; wealth=(c1*c2*c3*c4*c5); gm=((wealth)**(1/t))-1; gm_pct=gm*100; am=mean(of col1-col5); am_pct=am*100; run; /* Example Code Found on Page 13 */ /* SP4 Data Set Created in Example Code on Page 11 */ data sp5a; set sp4; t=5; array col(5) col1-col5; array c(5) c1-c5; do i=1 to 5; c(i) = col(i) + 1; end; wealth=(c1*c2*c3*c4*c5); gm=((wealth)**(1/t))-1; gm_pct=gm*100; am=mean(of col1-col5); am_pct=am*100; run; /* SP5 Data Set Created in Example Code on Page 12 */ proc print data=sp5; var wealth gm gm_pct am am_pct; title2 'Multiple Period Return Measures'; run; /* Example Code Found on Page 15 */ /* SP3 Data Set Created in Example Code on Page 11 */ proc means data=sp3 mean; var r r_per; title2 'Mean Returns'; run; /* Example Code Found on Pages 16-17 */ data d1; input r p1 p2 p3 p4; array p(4) p1-p4; array lc(4) lc1-lc4; do i=1 to 4; lc(i)=r*p(i); end; cards; -.10 0 .05 0 0 -.05 .05 .10 0 .10 0 .25 .20 .20 .10 .05 .40 .30 .30 .20 .10 .20 .20 .30 .30 .15 .10 .10 .20 .20 .20 0 .05 0 .10 ; proc means data=d1 sum noprint; var lc1-lc4; output out=out_d1 sum=mean1-mean4; run; proc print data=out_d1; var mean1-mean4; title2 'Discrete Distribution Mean Returns'; run; /* Example Code Found on Page 18 */ /* SP5 Data Set Created in Example Code on Page 12 */ data sp6; set sp5; r_am = col5*(am+1); r_gm = col5*(gm+1); run; proc print data=sp6; var col5 r_am r_gm; title2 'Future Returns'; title3 'Calculating with Past Growth Rates'; run; /* Example Code Found on Page 20 */ /* SP3 Data Set Created in Example Code on Page 11 */ proc means data=sp3 mean var std; var r; title2 'Mean, Variance, and Standard Deviation'; title3; run; /* Example Code Found on Page 21 */ /* D1 Data Set Created in Example Code on Pages 16-17 */ /* OUT_D1 Data Set Created in Example Code on Page 17 */ data out_d2; set out_d1; do i=1 to 7; output; end; run; data d2; merge d1 out_d2; array p(4) p1-p4; array m(4) mean1-mean4; array vv(4) vv1-vv4; do i=1 to 4; vv(i)=p(i)*(r-m(i))**2; end; run; proc means data=d2 sum noprint; var vv1-vv4; output out=out_d3 sum=var1-var4; run; proc print data=out_d3; var var1-var4; title2 'Discrete Distribution Variance'; run; /* Example Code Found on Pages 21-22 */ data d3; set out_d3; array vv(4) var1-var4; array stt(4) std1-std4; do i=1 to 4; stt(i)=sqrt(vv(i)); end; run; proc print data=d3; var std1-std4; title2 'Discrete Distribution Standard Deviation'; run; /* Chapter 2 */ /* Example Code Found on Page 25 */ data dcf1; input firm $20. d hi lo; k=.0932; v=round(d/k, .001); label d='Dividend' v='Value' hi='High Price 1990' lo='Low Price 1990'; cards; Pub Service Colorado 2.00 26.500 20.000 Puget Sound Power 1.76 22.500 18.625 WA Water Power 2.48 31.000 26.875 Wendy's 0.24 7.500 3.875 Westcoast Energy 0.80 19.625 16.750 Whirlpool 1.10 33.500 17.500 Williams Companies 1.40 40.625 23.125 Wyle Laboratories 0.28 15.125 8.750 Xerox 3.00 58.875 29.000 ; proc print data=dcf1 label; var firm d hi v lo; title 'DCF Analysis'; title2 'Fixed Dollar Dividends'; run; /* Example Code Found on Pages 28-29 */ data dcf2; input year stock1 stock2 stock3 stock4 stock5 stock6 stock7 stock8 stock9 stock10 stock11 stock12 stock13 stock14 stock15 stock16 stock17 stock18 stock19 stock20 stock21 stock22 stock23; array stock{23} stock1-stock23; array lstock{23} lstock1-lstock23; do i=1 to 23; lstock{i}=log(stock{i}); end; year2=year*year; label stock1='3M Company' stock2='Allegheny Power' stock3='Cincinnati G&E' stock4='Detroit Edison' stock5='Dominion Resources' stock6='Duke Power' stock7='Eli Lilly' stock8='Green Mountain Power' stock9='Iowa-Ill Gas & Electric' stock10='Kansas Power & Light' stock11='Kentucky Utilities' stock12='Minnesota Power & Light' stock13='Northern States Power' stock14='Oklahoma Gas & Electric' stock15='Orange & Rockland Utilities' stock16='Pennsylvania Power & Light' stock17='Piedmont Natural Gas' stock18='Potomac Electric Power' stock19='TECO Energy' stock20='Texas Utilities' stock21='Union Electric' stock22='Wisconsin Energy' stock23='Wicor' lstock1='Natural Log 3M Company' lstock2='Natural Log Allegheny Power'; cards; 81 1.50 2.01 2.07 1.62 1.43 1.04 .58 1.44 1.10 1.08 1.06 1.06 1.25 1.68 1.64 2.21 .87 .79 .84 1.85 1.52 .88 1.05 82 1.60 2.28 2.12 1.68 1.53 1.12 .67 1.52 1.18 1.18 1.10 1.14 1.33 1.76 1.74 2.30 .93 .84 .92 2.00 1.58 .95 1.07 83 1.65 2.50 2.16 1.68 1.63 1.16 .69 1.60 1.24 1.26 1.14 1.20 1.43 1.84 1.86 2.38 .97 .89 1.00 2.16 1.66 1.03 1.07 84 1.70 2.63 2.16 1.68 1.73 1.21 .75 1.68 1.30 1.36 1.18 1.28 1.55 1.92 1.98 2.46 1.07 .97 1.08 2.32 1.72 1.12 1.11 85 1.75 2.70 2.16 1.68 1.83 1.27 .80 1.74 1.37 1.46 1.22 1.38 1.69 2.00 2.09 2.56 1.16 1.08 1.16 2.48 1.78 1.22 1.18 86 1.80 2.86 2.16 1.68 1.91 1.32 .90 1.78 1.45 1.56 1.26 1.52 1.83 2.08 2.16 2.57 1.19 1.18 1.24 2.64 1.86 1.32 1.28 87 1.86 2.94 2.18 1.68 1.99 1.37 1.00 1.83 1.52 1.63 1.29 1.66 1.96 2.18 2.20 2.66 1.29 1.30 1.32 2.77 1.92 1.42 1.30 88 2.12 3.02 2.23 1.68 2.07 1.44 1.15 1.89 1.59 1.70 1.34 1.72 2.07 2.28 2.24 2.74 1.44 1.38 1.40 2.86 1.94 1.52 1.32 89 2.60 3.10 2.30 1.68 2.15 1.52 1.35 1.95 1.63 1.75 1.40 1.78 2.17 2.38 2.28 2.84 1.57 1.46 1.50 2.91 2.02 1.63 1.37 90 2.82 3.16 2.40 1.76 2.23 1.60 1.64 2.00 1.67 1.79 1.46 1.86 2.27 2.48 2.32 2.95 1.66 1.52 1.60 2.96 2.10 1.74 1.42 ; proc plot data=dcf2 vpct=110; plot (stock1-stock3)*year; title2; run; /* Example Code Found on Page 31 */ /* DCF2 Data Set Created in Example Code on Pages 28-29 */ proc plot data=dcf2 vpct=110; plot lstock1*year; title2 'Semi-Log Plot'; title3 '3M Company Dividends'; run; /* Example Code Found on Pages 32-33 */ /* DCF2 Data Set Created in Example Code on Pages 28-29 */ proc reg data=dcf2 outest=dcf_est1(rename=(year=f year2=h)) noprint; model stock1=year year2 / adjrsq; model stock2=year year2 / adjrsq; model stock3=year year2 / adjrsq; model stock4=year year2 / adjrsq; model stock5=year year2 / adjrsq; model stock6=year year2 / adjrsq; model stock7=year year2 / adjrsq; model stock8=year year2 / adjrsq; model stock9=year year2 / adjrsq; model stock10=year year2 / adjrsq; model stock11=year year2 / adjrsq; model stock12=year year2 / adjrsq; model stock13=year year2 / adjrsq; model stock14=year year2 / adjrsq; model stock15=year year2 / adjrsq; model stock16=year year2 / adjrsq; model stock17=year year2 / adjrsq; model stock18=year year2 / adjrsq; model stock19=year year2 / adjrsq; model stock20=year year2 / adjrsq; model stock21=year year2 / adjrsq; model stock22=year year2 / adjrsq; model stock23=year year2 / adjrsq; run; data dcf_est2; set dcf_est1; k=.0932; gq=f+2*h*90; if gq ge k then caution1= 'YES'; else caution1 = 'NO '; run; proc print data=dcf_est2; var _depvar_ _rsq_ _adjrsq_ intercep f h gq caution1; title2 'Fitted Quadratic Models'; title3 'and Growth Rate of Dividends'; run; /* Example Code Found on Page 35 */ /* DCF2 Data Set Created in Example Code on Pages 28-29 */ proc reg data=dcf2 outest=dcf_est3(rename=(year=gl)) noprint; model lstock1=year / adjrsq; model lstock2=year / adjrsq; model lstock3=year / adjrsq; model lstock4=year / adjrsq; model lstock5=year / adjrsq; model lstock6=year / adjrsq; model lstock7=year / adjrsq; model lstock8=year / adjrsq; model lstock9=year / adjrsq; model lstock10=year / adjrsq; model lstock11=year / adjrsq; model lstock12=year / adjrsq; model lstock13=year / adjrsq; model lstock14=year / adjrsq; model lstock15=year / adjrsq; model lstock16=year / adjrsq; model lstock17=year / adjrsq; model lstock18=year / adjrsq; model lstock19=year / adjrsq; model lstock20=year / adjrsq; model lstock21=year / adjrsq; model lstock22=year / adjrsq; model lstock23=year / adjrsq; title 'DCF Analysis'; title2 'Semi-Log Model of Dividends'; run; proc print data=dcf_est3; var _depvar_ _rsq_ _adjrsq_ intercep gl; title2 'Fitted Semi-Log Models'; title3 'and Growth Rate of Dividends'; run; /* Example Code Found on Page 37 */ /* DCF2 Data Set Created in Example Code on Pages 28-29 */ proc transpose data=dcf2 out=dcf_tr1; var stock1-stock23; run; proc print data=dcf_tr1 (obs=5); var _label_ col1 col10; title2 'First Five Observations'; title3 'Transposed DCF2 Data Set'; title4 'Firm, 1981 and 1990 Dividends'; run; /* Example Code Found on Pages 37-38 */ data dcf_tr2; set dcf_tr1; t=10; gc=((col10/col1)**(1/t))-1; label gc='Annually Compounded Growth Rate'; run; proc print data=dcf_tr2 (obs=10); var _label_ gc; title2 'Annually Compounded Growth Rate'; title3; title4; run; /* Example Code Found on Pages 38-39 */ /* DCF_TR2 Data Set Created in Example Code on Pages 37-38 */ /* DCF_EST2 Data Set Created in Example Code on Pages 32-33 */ /* DCF_EST3 Data Set Created in Example Code on Page 35 */ data dcf_cal1; merge dcf_tr2 dcf_est2 dcf_est3; d0=col10; k=.0932; d1q=round(d0*(1+gq), .001); vq=round(d1q/(k-gq), .001); d1l=round(d0*(1+gl), .001); vl=round(d1l/(k-gl), .001); d1c=round(d0*(1+gc), .001); vc=round(d1c/(k-gc), .001); label k='Discount Rate' d0='1990 Dividend' gq='Quadratic Model Growth Rate' d1q='Quadratic Model Next Dividend' vq='Quadratic Model DCF Value' gl='Semi-Log Model Growth Rate' d1l='Semi-Log Model Next Dividend' vl='Semi-Log Model DCF Value' d1c='Compound Growth Rate Next Dividend' vc='Compound Growth DCF Value'; run; proc print data=dcf_cal1 label; var _label_ gq gl gc k; title2 'Growth Rates'; run; /* Example Code Found on Page 40 */ /* DCF_CAL1 Data Set Created in Example Code on Pages 38-39 */ proc print data=dcf_cal1 label; var _label_ d0 d1q d1l d1c; title2 'Next Period (1991) Dividends'; run; proc print data=dcf_cal1 label; var _label_ vq vl vc; title2 'DCF Values'; run; /* Example Code Found on Page 43 */ data dcf3; input year d @@; label d='Detroit Edison Dividends'; cards; 82 1.68 83 1.68 84 1.68 85 1.68 86 1.68 87 1.68 88 1.68 89 1.68 90 1.76 91 1.76 92 1.76 93 1.76 ; proc plot data=dcf3 vpct=110; plot d*year='*' / href=90; title2 'Dividends Versus Time'; run; /* Example Code Found on Page 44 */ data dcf_cal2; k=.0938; d1=1.68; d2=1.76; v0=round(d1/k, .01); v1=round(d1/(1+k), .01); v2=round(d1/((1+k)**2), .01); v3=round(d2/(k*(1+k)**2), .01); v=v1+v2+v3; label v0='DCF Value for $1.68 Dividend Series' v1='Discounted Value for 1988' v2='Discounted Value for 1989' v3='DCF Value for $1.76 Dividend Series' v='DCF Value for Two Periods'; run; proc print data=dcf_cal2 label; var v0 v1 v2 v3 v; title2 'Discounted Cash Flow Values'; run; /* Example Code Found on Page 47 */ data dcf4; input year d @@; t=5; d1990=1.29; d1995=5.85; gc1=(d1995/d1990)**(1/t); d1=round(d1990*(gc1**(year-1990)), .001); cards; 1990 1.29 1991 . 1992 . 1993 . 1994 . 1995 5.85 ; proc reg data=dcf4 noprint; model d=year; output out=dcf_out1 p=d2; run; proc print data=dcf_out1; var year d d1 d2; title2 'Predicted Dividends Over Time'; title3 'Compound Growth Rate and Linear Trend'; run; /* Example Code Found on Pages 48-49 */ /* DCF4 Data Set Created in Example Code on Page 47 */ data dcf5; set dcf4; if year=1992 then d=4.24; year2=year*year; run; data dcf6; set dcf4; if year=1994 then d=4.76; year2=year*year; run; proc reg data=dcf5 noprint; model d=year year2; output out=dcf_out2 p=d3; run; proc reg data=dcf6 noprint; model d=year year2; output out=dcf_out3 p=d4; run; proc print data=dcf_out2; var year d d3; title2 'Predicted Dividends Over Time'; title3 'Rapid Initial Growth Quadratic Model'; run; proc print data=dcf_out3; var year d d4; title3 'Slow Initial Growth Quadratic Model'; run; /* Example Code Found on Pages 49-50 */ /* DCF_OUT1 Data Set Created in Example Code on Page 47 */ /* DCF_OUT2 Data Set Created in Example Code on Pages 48-49 */ /* DCF_OUT3 Data Set Created in Example Code on Pages 48-49 */ data dcf7; merge dcf_out1 dcf_out2 dcf_out3; by year; run; proc transpose data=dcf7 out=dcf_tr3; var d1-d4; run; data dcf8; set dcf_tr3; k=.0932; yr91=col2/(1+k); yr92=col3/((1+k)**2); yr93=col4/((1+k)**3); yr94=col5/((1+k)**4); yr95=col6/(k*((1+k)**4)); v=sum(of yr91-yr95); run; proc print data=dcf8; var yr91-yr95 v; title2 'Calculated DCF Values'; title3 'and Predicted Dividends Over Time'; run; /* Example Code Found on Pages 51-52 */ data dcf9; input firm $32. pe pr; label pe='Price Earnings Ratio 1990' pr='Dividend Payout Ratio 1990'; cards; 3M Company 14.0 48 Allegheny Power 10.5 88 Cincinnati G&E 7.3 58 Detroit Edison 8.2 54 Dominion Resources 10.3 76 Duke Power 12.1 67 Eli Lilly 19.1 42 Green Mountain Power 10.8 87 Iowa-Ill Gas & Electric 10.6 84 Kansas Power & Light 10.0 80 Kentucky Utilities 9.9 74 Minnesota Power & Light 10.5 78 Northern States Power 12.3 81 Oklahoma Gas & Electric 10.7 73 Orange & Rockland Utilities 9.8 78 Pennsylvania Power & Light 10.6 75 Piedmont Natural Gas 11.3 68 Potomac Electric Power 13.0 94 TECO Energy 12.3 65 Texas Utilities 8.1 67 Union Electric 10.0 77 Wisconsin Energy 10.7 63 Wicor 20.9 . ; proc means data=dcf2 noprint; var stock1-stock23; output out=dcf_std1 std=std1-std23; run; proc transpose data=dcf_std1 out=dcf_std2(rename=(col1=std)); var std1-std23; run; proc print data=dcf_std2 (obs=5); var std; title2 'Standard Deviations of Dividends'; title3 'First Five Observations'; run; /* Example Code Found on Pages 53 */ /* DCF9 Data Set Created in Example Code on Pages 51-52 */ /* DCF_STD2 Data Set Created in Example Code on Pages 51-52 */ /* DCF_CAL1 Data Set Created in Example Code on Pages 38-39 */ data dcf_cal2; merge dcf9 dcf_std2 dcf_cal1; run; proc print data=dcf_std2 (obs=5); var pe gc pr std; title2 'Cross-Sectional Multiple Regression Data'; title3 'First Five Observations'; run; /* Example Code Found on Page 54 */ /* DCF_CAL2 Data Set Created in Example Code on Page 53 */ proc reg data=dcf_cal2; model pe=gc pr std; output out=dcf_reg1 p=p r=r; run; /* Example Code Found on Page 55 */ /* DCF_REG1 Data Set Created in Example Code on Page 54 */ proc plot data=dcf_reg1 vpct=125; plot r*gc='*' / vref=0; title2 'PE Regression Residuals'; title3 'versus Compound Growth Rate'; run; /* Example Code Found on Page 56 */ /* DCF_REG1 Data Set Created in Example Code on Page 54 */ data dcf_reg2; set dcf_reg1; if r=. then hi_lo='.....'; else if r>0 then hi_lo='Over '; else if r=0 then hi_lo='0 '; else if r<0 then hi_lo='Under'; run; proc print data=dcf_reg2; var firm r hi_lo; title2 'Regression Residuals and'; title3 'Over- and Undervalued Variable, HI_LO'; run; /* Chapter 3 */ /* Example Code Found on Page 60 */ /* DCF9 Data Set Created in Example Code on Pages 51-52 */ proc sort data=dcf9 out=dcf9a; by pe; run; proc print data=dcf9a (obs=5) label; title 'Sorting and Clustering Stocks'; title2 'Sorting Stocks by PE Ratios'; run; /* Example Code Found on Page 61 */ /* DCF9A Data Set Created in Example Code on Page 60 */ data dcf9b; set dcf9a (obs=15); run; proc print data=dcf9b label; title2 'Stocks with Lowest PE Ratios'; run; /* Example Code Found on Page 62 */ /* DCF9 Data Set Created in Example Code on Pages 51-52 */ proc sort data=dcf9 out=dcf9a1; by pe pr; run; proc sort data=dcf9 out=dcf9a2; by pe descending pr; run; /* Example Code Found on Page 63 */ data dcf10; input year cin txu dte oru ku kan uep d ayp mpl iwg ppl oge wse gmp; label cin='Cincinnati G&E' txu='Texas Utilities' dte='Detroit Edison' oru='Orange & Rockland Utilities' ku='Kentucky Utilities' kan='Kansas Power & Light' uep='Union Electric' d='Dominion Resources' ayp='Allegheny Power' mpl='Minnesota Power & Light' iwg='Iowa-Ill Gas & Electric' ppl='Pennsylvania Power & Light' oge='Oklahoma Gas & Electric' wse='Wisconsin Energy' gmp='Green Mountain Power'; cards; 1986 8.4 7.9 9.7 6.5 6.5 5.9 7.1 6.7 6.7 5.6 7.1 7.2 6.1 5.1 7.1 1987 8.2 8.9 10.7 7.2 6.9 6.4 7.5 6.9 7.3 6.1 7.5 7.6 6.7 5.7 7.4 1988 8.4 10.4 11.4 7.3 7.0 6.9 8.4 7.0 7.8 7.2 8.5 7.7 7.4 6.0 7.8 1989 8.1 8.9 7.8 7.7 7.2 7.4 7.8 7.0 7.9 7.0 7.8 7.4 6.7 5.7 7.8 1990 8.0 8.3 6.5 7.9 7.5 8.0 7.7 7.4 8.3 7.5 8.0 7.1 6.8 5.9 8.3 ; proc plot data=dcf10 vpct=200; plot cin * year ='c' txu * year ='t' dte * year ='d' oru * year ='o' ku * year ='k'/ overlay; title2 'Plotting Dividend Yields 1986-1990'; run; /* Example Code Found on Page 65 */ /* DCF10 Data Set Created in Example Code on Page 63 */ proc corr data=dcf10 outp=dcf10a nosimple; var cin txu dte oru ku kan uep d ayp mpl iwg ppl oge wse gmp; title2 'Part of the Correlation Matrix'; run; /* Example Code Found on Page 66 */ /* DCF10A Data Set Created in Example Code on Page 65 */ proc print data=dcf10a (obs=10) label; var _type_ _name_ cin txu dte; title2 'PROC CORR Output Data Set, DCF10A'; run; /* Example Code Found on Page 67 */ /* DCF10A Data Set Created in Example Code on Page 65 */ data dcf10b (drop=_type_); set dcf10a; if _type_='CORR'; run; proc sort data=dcf10b out=dcf10b1; by cin; run; proc print data=dcf10b1; var _name_ cin; title2 'Sorted Correlation Matrix'; run; /* Example Code Found on Page 69 */ /* DCF10B Data Set Created in Example Code on Page 67 */ data dist1(type=distance); set dcf10b; cin_d=1-cin; txu_d=1-txu; dte_d=1-dte; oru_d=1-oru; ku_d =1-ku; kan_d=1-kan; uep_d=1-uep; d_d =1-d; ayp_d=1-ayp; mpl_d=1-mpl; iwg_d=1-iwg; ppl_d=1-ppl; oge_d=1-oge; wse_d=1-wse; gmp_d=1-gmp; run; proc print data=dist1 (obs=8) label; title2 'Dissimilarity Distance Matrix'; run; /* Example Code Found on Page 72 */ /* DIST1 Data Set Created in Example Code on Page 69 */ proc cluster data=dist1 method=density k=2 outtree=clust1; var cin_d txu_d dte_d oru_d ku_d kan_d uep_d d_d ayp_d mpl_d iwg_d ppl_d oge_d wse_d gmp_d; id _name_ ; title 'Sorting and Clustering Stocks'; title2 'Record of Clustering'; run; /* Example Code Found on Page 74 */ /* DIST1 Data Set Created in Example Code on Page 69 */ proc cluster data=dist1 method=density r=.1 outtree=clust2; var cin_d txu_d dte_d oru_d ku_d kan_d uep_d d_d ayp_d mpl_d iwg_d ppl_d oge_d wse_d gmp_d; id _name_ ; run; /* Example Code Found on Pages 76-77 */ /* DIST1 Data Set Created in Example Code on Page 69 */ proc cluster data=dist1 method=single outtree=clust3; var cin_d txu_d dte_d oru_d ku_d kan_d uep_d d_d ayp_d mpl_d iwg_d ppl_d oge_d wse_d gmp_d; id _name_ ; run; proc cluster data=dist1 method=average outtree=clust4; var cin_d txu_d dte_d oru_d ku_d kan_d uep_d d_d ayp_d mpl_d iwg_d ppl_d oge_d wse_d gmp_d; id _name_ ; run; proc cluster data=dist1 method=centroid outtree=clust5; var cin_d txu_d dte_d oru_d ku_d kan_d uep_d d_d ayp_d mpl_d iwg_d ppl_d oge_d wse_d gmp_d; id _name_ ; run; proc cluster data=dist1 method=complete outtree=clust6; var cin_d txu_d dte_d oru_d ku_d kan_d uep_d d_d ayp_d mpl_d iwg_d ppl_d oge_d wse_d gmp_d; id _name_ ; run; /* Example Code Found on Page 81 */ /* CLUST1 Data Set Created in Example Code on Page 72 */ proc tree data=clust1 horizontal; title 'Sorting and Clustering Stocks'; title2 'K-th Nearest Neighbor Clustering'; title3 'Tree Diagram'; run; /* Example Code Found on Page 82 */ /* CLUST2 Data Set Created in Example Code on Page 74 */ proc tree data=clust2 horizontal; title2 'R-Radius Density Linkage Clustering'; title3 'Tree Diagram'; run; /* CLUST3 Data Set Created in Example Code on Pages 76-77 */ proc tree data=clust3 maxheight=.35 minheight=0 horizontal; title2 'Single Linkage Clustering Tree Diagram'; title3; run; /* CLUST4 Data Set Created in Example Code on Pages 76-77 */ proc tree data=clust4 maxheight=1.8 minheight=0 horizontal; title2 'Average Linkage Clustering Tree Diagram'; run; /* CLUST5 Data Set Created in Example Code on Pages 76-77 */ proc tree data=clust5 maxheight=1.8 minheight=0 horizontal; title2 'Centroid Linkage Clustering Tree Diagram'; run; /* CLUST6 Data Set Created in Example Code on Pages 76-77 */ proc tree data=clust6 maxheight=3.25 minheight=0 horizontal; title2 'Complete Linkage Clustering Tree Diagram'; run; /* Example Code Found on Page 87 */ /* CLUST3 Data Set Created in Example Code on Pages 76-77 */ proc tree data=clust3 nclusters=3 out=clust3a noprint; run; proc print data=clust3a; title2 'Three Clusters of the'; title3 'Single Linkage Clustering'; run; /* Chapter 4 */ /* Example Code Found on Pages 93-94 */ data return1; input r_m r_f gerber @@; retain date '01dec77'd; date=intnx('month',date,1); format date monyy.; /* Creating of New Variables */ r_gerber = gerber - r_f; r_mkt = r_m - r_f; /* Labeling Variables */ label r_m='Market Rate of Return' r_f='Risk-Free Rate of Return' gerber='Rate of Return for Gerber Corporation' r_gerber='Risk Premium for Gerber Corporation' r_mkt='Risk Premium for Market'; cards; -.045 .00487 -.048 .010 .00494 .160 .050 .00526 -.036 .063 .00491 .004 .067 .00513 .046 .007 .00527 .028 .071 .00528 -.012 .079 .00607 -.079 .002 .00645 .104 -.189 .00685 -.138 .084 .00719 .078 .015 .00690 -.086 .058 .00761 .042 .011 .00761 -.023 .123 .00769 .065 .026 .00764 -.088 .014 .00772 -.023 .075 .00715 .095 -.013 .00728 -.096 .095 .00789 .148 .039 .00802 -.009 -.097 .00913 -.090 .116 .00819 -.014 .086 .00747 -.036 .124 .00883 .048 .112 .01073 -.004 -.243 .01181 -.237 .080 .00753 .027 .062 .00630 .233 .086 .00503 .011 .065 .00602 .005 .025 .00731 -.008 .015 .00860 .066 .006 .00895 .026 .092 .01137 .023 -.056 .00977 .070 -.014 .01092 .056 -.009 .01096 -.020 .067 .01025 .023 -.008 .01084 .031 .064 .01255 .008 -.003 .01128 .066 -.033 .01154 .021 -.031 .01169 .031 -.164 .01054 .000 .062 .01003 -.012 .069 .00816 .011 -.039 .00740 -.077 -.079 .00949 -.004 -.101 .00946 -.111 -.028 .01067 .136 .041 .00972 .044 .003 .00908 .043 -.078 .00914 -.033 -.006 .00714 .019 .122 .00503 .130 .008 .00563 .209 .136 .00620 -.009 .049 .00614 -.072 .014 .00648 .015 .065 .00646 .015 .028 .00599 .024 .043 .00686 .084 .097 .00652 .119 .080 .00649 .016 .048 .00673 .114 -.017 .00714 -.007 -.034 .00668 .062 .000 .00702 .049 -.082 .00678 .000 .066 .00683 .077 -.012 .00693 .063 -.029 .00712 .065 -.030 .00672 -.091 .003 .00763 -.003 -.003 .00741 -.025 -.058 .00627 -.087 .005 .00748 .105 -.058 .00771 -.112 .146 .00852 .018 .000 .00830 .165 -.035 .00688 -.160 -.019 .00602 .094 -.001 .00612 -.005 .097 .00606 .091 .012 .00586 .006 .008 .00650 .013 -.010 .00601 -.037 .019 .00512 .234 -.003 .00536 -.031 .012 .00562 -.036 .005 .00545 .025 -.055 .00571 -.048 .026 .00577 .097 .059 .00540 .137 .013 .00479 .063 -.009 .00548 -.088 .049 .00523 .034 .048 .00508 .174 -.009 .00444 .113 .049 .00469 -.040 .004 .00478 -.038 -.076 .00458 -.105 .049 .00343 .111 -.047 .00416 .037 .018 .00418 -.069 .000 .00420 -.020 -.005 .00382 -.060 ; proc print data=return1 (obs=5) label; var date r_gerber r_mkt r_m r_f gerber; title 'CAPM Analysis'; title2 'Returns and Risk Premiums'; run; /* Example Code Found on Page 95 */ /* RETURN1 Data Set Created in Example Code on Pages 93-94 */ proc plot data=return1 vpct=125; plot r_gerber*r_mkt = '*' / href=0; title2 'Gerber Corporation Stock Premiums'; title3 'Versus Market Premiums'; run; /* Example Code Found on Page 97 */ /* RETURN1 Data Set Created in Example Code on Pages 93-94 */ /* Only 1st 12 Observations Are Shown in Output */ proc timeplot data=return1 maxdec=5; plot r_gerber='G' r_mkt='M' r_f='F' / overlay; plot gerber='G' r_m='M' r_f='F' / overlay; id date; title2 'Time Plot'; title3 'Gerber, Market, and Risk Free'; run; /* Example Code Found on Page 99 */ /* RETURN1 Data Set Created in Example Code on Pages 93-94 */ proc reg data=return1; model r_gerber = r_mkt / dw spec; output out=r_out1 r=r1 p=p l95=l u95=u; slope: test r_mkt=1; title2 'Gerber Corporation Common Stock'; title3; run; /* Example Code Found on Pages 102-103 */ /* R_OUT1 Data Set Created in Example Code on Page 99 */ proc print data=r_out1 (obs=5); var date r_gerber u p1 l gerber_r; title2 'Actual, Predicted, and Residual Values'; title3 'with Upper and Lower Confidence Limits'; run; proc plot data=r_out1 vpct=125; plot gerber_r*date='*' / vref=0 vaxis=-.25 to .25 by .1 haxis='01dec77'd to '31dec86'd by year; title2 'Gerber Residuals versus Date'; title3; run; /* Example Code Found on Page 104 */ /* R_OUT1 Data Set Created in Example Code on Page 99 */ proc plot data=r_out1 vpct=125; plot gerber_r*r_mkt='*' / vref=0 vaxis=-.25 to .25 by .1; title2 'Gerber Residuals versus R_MKT'; title3; run; /* Example Code Found on Pages 105-107 */ /* R_OUT1 Data Set Created in Example Code on Page 99 */ goptions reset=global gunit=pct cback=white border htitle=6 htext=3 ftext=swissb colors=(black); proc sort data=r_out1; by r_mkt; run; /* Assigning Labels to Variables for PROC GPLOT Legend */ data regdata (keep=y_value pt_type r_mkt); set r_out1; label pt_type='Observation Type'; array regvar(4) r_gerber p1 l u; array varlabel(4) $12 _temporary_ ('Actual' 'Predicted' 'Lower Limits' 'Upper Limits'); do i=1 to 4; y_value=regvar(i); pt_type=varlabel(i); output; end; run; proc gplot data=regdata; plot y_value*r_mkt=pt_type / haxis=axis1 vaxis=axis2 hminor=4 vminor=4; symbol1 v=* h=3.5 pct font=swissb color=black; symbol2 i=join font=swissb l=2 color=blue; symbol3 i=join font=swissb l=1 color=green; symbol4 i=join font=swissb l=2 color=red; axis1 order=(-.3 to .15 by .05); axis2 label=(angle=90 'Gerber Stock Risk Premium') order=(-.5 to .5 by .25); title1 'Actual and Predicted Values'; title2 'with Upper and Lower Confidence Limits'; run; quit; /* Example Code Found on Pages 109-112 */ data return2; input tandy genmil coned weyer ibm dec mobil tex cpl @@; retain date '01dec77'd; date=intnx('month',date,1); format date monyy.; label tandy='Rate of Return for Tandy Corporation' genmil='Rate of Return for General Mills' coned='Rate of Return for Con Edison' weyer='Rate of Return for Weyerhauser' ibm='Rate of Return for IBM' dec='Rate of Return for DEC' mobil='Rate of Return for Mobil Corporation' tex='Rate of Return for Texaco' cpl='Rate of Return for CPL'; cards; -.075 -.099 -.079 -.116 -.029 -.100 -.046 -.054 -.069 -.004 .018 -.003 -.135 -.043 -.063 -.017 -.010 .006 .124 -.023 .022 .084 -.063 .010 .049 .015 .017 .055 .046 -.005 .144 .130 .165 .077 .000 -.063 .176 .063 -.014 -.031 -.018 .038 -.011 -.029 .091 -.014 .008 .034 .005 -.004 -.021 -.043 -.025 .021 .194 .075 .011 .164 .092 .107 .028 .042 .034 .222 -.051 .024 .039 .049 -.017 .056 .000 -.011 -.100 -.012 .048 -.021 -.051 -.037 .064 .010 .033 -.206 -.032 -.067 -.090 -.046 -.077 -.069 -.066 -.117 .086 .009 .035 -.033 .031 .064 .037 .055 .067 .085 .022 .005 -.034 .108 .117 .041 .000 .011 -.046 -.032 .076 .203 .034 -.012 .061 .037 .029 -.135 -.079 -.011 -.038 -.017 -.066 -.002 -.010 -.028 .122 -.043 .000 .097 .052 .088 .029 .068 .006 -.094 .022 -.057 -.069 -.004 .005 .079 .059 -.099 -.148 .035 .032 -.013 -.022 -.028 -.086 -.040 .059 .096 -.043 .066 .053 -.035 .059 .088 .083 .069 .006 -.013 .015 .000 -.049 .009 .018 .032 -.042 .250 .138 -.021 .165 .016 .140 .111 .041 .025 -.005 -.032 .000 -.015 -.032 -.027 .180 .030 .006 -.037 -.067 -.049 -.083 -.079 -.010 -.031 -.053 -.083 .170 .005 .109 -.065 .060 .095 .051 .067 .041 .037 .005 .005 .104 -.013 .018 .063 -.029 -.006 .032 .003 -.039 .069 .066 .058 .075 .229 -.071 .143 -.096 -.061 .033 -.062 .034 .366 .161 -.072 -.105 .011 .006 -.129 -.122 -.182 -.176 -.179 .047 -.038 .059 .140 .027 -.016 .047 .119 .082 .188 .256 .018 .043 .089 .025 .016 .003 .007 .006 .041 -.013 .040 -.026 .061 .021 -.024 .032 .103 .446 .012 -.027 .140 .111 .183 .054 .003 -.032 .167 .018 -.005 -.041 .017 .081 -.059 .031 -.025 .157 -.013 -.010 -.064 -.021 .045 .007 -.037 -.025 -.015 -.073 -.021 .017 .039 -.028 .059 .087 -.075 .212 -.030 -.035 .015 .035 .056 .193 .399 .000 .022 .102 .131 .007 -.004 .035 -.081 -.109 .051 -.139 .079 -.015 .028 -.052 -.089 -.082 -.145 .010 .082 .013 -.021 .025 .011 .006 -.067 -.012 -.035 .299 .146 .151 .088 -.029 .075 -.042 -.063 .066 .092 .019 .061 -.050 -.060 .075 -.025 -.003 .017 .136 .030 .017 -.031 .017 .107 -.092 -.055 .049 -.167 .094 .022 .021 -.015 -.112 .053 .025 .026 .032 -.045 .026 -.081 -.030 -.014 .021 .045 -.003 -.063 -.031 .021 -.061 -.002 -.065 -.057 .003 .027 -.008 .036 -.013 -.113 -.018 -.019 -.106 -.093 -.006 .241 .067 .112 -.020 -.048 .102 .025 .008 .031 -.037 -.030 .038 .179 .075 -.065 .038 .065 .065 -.046 -.024 -.008 -.072 .044 -.060 -.090 -.047 -.006 .059 -.030 .042 -.079 .119 .027 -.016 -.045 .054 -.101 .098 .036 .014 -.014 -.049 -.016 -.004 .012 -.051 .020 .022 -.009 -.034 -.104 -.038 -.029 .054 .053 .076 .050 .059 .075 .054 -.011 -.008 .016 -.163 -.027 .016 -.086 -.029 -.056 .092 .034 -.023 .023 .050 -.024 -.015 -.014 -.073 -.038 -.017 -.047 .050 .038 -.032 -.012 .082 -.055 -.073 -.060 -.007 .017 .032 .133 .221 .087 .273 .157 .056 .108 -.026 .000 .039 -.029 .041 -.061 .043 .027 -.098 .454 .160 -.050 .150 .089 .133 .020 .056 .056 .273 -.025 -.011 .141 .094 .175 -.040 .012 .025 -.042 -.020 .123 -.040 .113 -.052 .069 .029 .042 .091 -.039 -.012 .023 .027 .225 .055 .036 .080 .032 .067 .060 .065 .010 -.010 .009 .008 -.006 -.004 .061 .048 -.023 .028 .034 .095 .039 .006 .084 .066 .045 .091 .150 -.060 .091 .098 -.007 -.010 .023 -.012 -.067 -.041 -.052 -.052 -.038 .023 -.168 -.026 .000 -.013 .081 .075 .077 .018 .000 -.123 -.072 .017 -.071 .001 -.142 -.060 .036 -.007 -.048 -.010 -.023 -.011 .001 .007 .118 .059 .006 -.083 -.037 .087 -.033 .062 -.005 -.050 -.037 .069 -.058 .116 .101 -.046 -.001 -.364 -.032 -.014 .065 .082 -.014 -.025 .151 -.066 .065 -.033 .011 -.005 .095 -.009 .005 -.069 .039 .034 .009 .021 -.057 -.190 -.009 .005 -.039 -.065 .208 .084 .108 .023 -.100 -.073 -.069 -.093 -.026 -.024 .024 .151 -.061 -.008 -.018 .055 .094 .034 .057 -.028 -.122 .024 .120 .065 .031 -.088 -.002 .053 .029 .022 -.029 -.231 .018 .021 -.087 -.044 -.071 -.146 -.105 -.006 -.037 .055 .020 .019 -.019 -.043 .010 -.046 .019 .029 -.018 .054 .036 .047 -.009 -.092 -.044 .006 .079 .061 .029 .055 .127 .159 .261 .140 .099 -.100 .011 .051 -.069 .004 -.025 .013 .045 .045 -.096 -.010 .019 .035 .012 .093 .014 -.080 .060 .027 -.072 .004 .032 -.023 .006 -.042 .007 .058 .005 .017 .084 .026 .011 .070 -.052 .000 .005 .170 .095 -.021 .084 .108 .084 .053 .044 .040 .119 .000 .034 -.016 -.009 -.067 .071 .022 -.019 .094 .054 .057 -.081 -.052 -.071 .000 .014 .069 -.133 -.083 .019 .003 -.004 -.050 .027 .111 .047 .091 .137 .098 .031 .025 .057 .029 -.065 .023 .087 .060 .046 -.004 -.038 -.101 -.032 .031 .066 -.119 -.099 -.084 .020 .062 .080 .002 -.030 -.095 .063 .002 .043 -.013 -.028 .032 -.013 .021 .014 -.011 .081 -.032 -.074 -.022 .036 .004 -.007 -.046 .098 .013 .066 .008 .048 .040 .100 .099 .098 .021 .114 .032 .171 .085 .073 -.008 -.175 .045 .098 .027 .082 -.004 .113 .095 -.040 -.077 .043 -.040 .019 .022 .072 -.026 .162 -.021 -.038 .047 .096 .121 .048 .123 .003 .093 -.003 .071 .069 -.047 .072 .021 .051 .004 -.063 -.026 -.004 .080 -.058 -.051 -.006 -.037 .031 .119 .042 .050 -.065 .094 .109 .042 .010 -.018 .037 .082 .069 .000 -.092 .071 .017 -.061 -.039 -.063 .012 -.042 .046 -.078 .049 .125 -.048 -.096 .066 -.022 -.036 .130 .018 .003 .061 .122 .055 .105 .173 .135 .112 -.108 -.088 -.139 -.058 -.031 -.110 .053 .026 -.077 .242 .123 .045 .135 -.081 .103 .020 .043 .040 .094 .011 .070 .006 .037 .048 .044 -.028 .006 -.023 -.034 -.046 -.041 -.056 .008 .019 .047 -.034 ; /* RETURN1 Data Set Created in Example Code on Pages 93-94 */ data return3; merge return1 return2; by date; r_tandy = tandy - r_f; r_genmil = genmil - r_f; r_coned = coned - r_f; r_weyer = weyer - r_f; r_ibm=ibm - r_f; r_dec=dec - r_f; r_mobil = mobil - r_f; r_tex=tex - r_f; r_cpl=cpl - r_f; label r_tandy='Risk Premium for Tandy Corporation' r_genmil='Risk Premium for General Mills' coned='Risk Premium for Con Edison' weyer='Risk Premium for Weyerhauser' ibm='Risk Premium for IBM' dec='Risk Premium for DEC' mobil='Risk Premium for Mobil Corporation' tex='Risk Premium for Texaco' cpl='Risk Premium for Carolina Power & Light'; run; proc print data=return3 (obs=10) label; var date r_tandy; title2 'Risk Premiums for Tandy Corporation'; run; /* Example Code Found on Page 113 */ /* RETURN3 Data Set Created in Example Code on Pages 109-112 */ proc reg data=return3 outest=capmest1; model r_tandy = r_mkt / dw spec; slope: test r_mkt=1; model r_genmil = r_mkt / dw spec; slope: test r_mkt=1; model r_coned = r_mkt / dw spec; slope: test r_mkt=1; model r_weyer = r_mkt / dw spec; slope: test r_mkt=1; model r_ibm = r_mkt / dw spec; slope: test r_mkt=1; model r_dec = r_mkt / dw spec; slope: test r_mkt=1; model r_mobil = r_mkt / dw spec; slope: test r_mkt=1; model r_tex = r_mkt / dw spec; slope: test r_mkt=1; model r_cpl = r_mkt / dw spec; slope: test r_mkt=1; run; /* Example Code Found on Page 119 */ /* CAPMEST1 Data Set Created in Example Code on Page 113 */ proc print data=capmest1; var _depvar_ intercep r_mkt; title2 'Estimated CAPM Regression Parameters'; run; /* Example Code Found on Page 120 */ /* CAPMEST1 Data Set Created in Example Code on Page 113 */ data forecast; set capmest1; do f_r_mkt = -.02 to .07 by .01; pred=intercep + f_r_mkt * r_mkt; risk_fre=.03; return = pred + risk_fre; output; end; label _depvar_='Stock' f_r_mkt='Future Market Risk Premium' pred='Predicted Stock Risk Premium' return='Predicted Future Stock Return'; run; proc print data=forecast (obs=10) label; var _depvar_ f_r_mkt pred return; title2 'Point Estimates of'; title3 'Stock Risk Premiums and Returns'; run; /* Example Code Found on Page 123 */ /* RETURN3 Data Set Created in Example Code on Pages 109-112 */ proc means data=return3 noprint; var r_gerber r_tandy r_genmil r_coned r_weyer r_ibm r_dec r_mobil r_tex r_cpl; output out=m_out1 mean=m1-m10; run; proc transpose data=m_out1 out=m_out2(rename=(col1=mean)); var m1-m10; run; proc print data=m_out2; title2 'Average Monthly Stock Returns'; run; /* Example Code Found on Pages 125-126 */ /* CAPMEST1 Data Set Created in Example Code on Page 113 */ /* M_OUT2 Data Set Created in Example Code on Page 123 */ data out_m3; merge capmest1(rename=(r_mkt=beta)) m_out2; m_mkt=.007783; sml=beta*(m_mkt); capm=intercep+beta*(mean); devia=capm-sml; if devia >= .01 then action='buy '; else if devia <= -.005 then action='sell'; else action='hold'; run; proc print data=out_m3; var capm sml devia action; title2 'Expected Risk Premiums'; title3 'and Actions to Consider'; run; /* Chapter 5 */ /* Example Code Found on Page 130 */ /* RETURN3 Data Set Created in Example Code on Pages 109-112 */ proc means data=return3 noprint; var gerber tandy genmil coned weyer ibm dec mobil tex cpl; output out=m_out1a mean=m1-m10; run; proc print data=m_out1a; var m1-m10; title 'Linear Programming'; title2 'Average Monthly Stock Returns'; run; /* Example Code Found on Page 135 */ data weight1; input _id_ $10. gerber tandy genmil coned weyer ibm dec mobil tex cpl _type_ $ _rhs_; cards; exp_return .0176 .0288 .0148 .021 .0092 .0103 .0182 .0172 .0121 .0146 max . beta .5309 1.048 .1383 .102 .7231 .3954 .7157 .6856 .5786 .2068 eq .7 sum_wts 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 eq 1.0 available 1 1 1 1 1 1 1 1 1 1 upperbd . available 0 0 0 0 0 0 0 0 0 0 lowerbd . ; proc lp data=weight1 primalout=lp_out1; title2 'Optimal Portfolio Weights'; run; quit; /* Example Code Found on Page 138 */ data weight2; input _id_ $10. gerber tandy genmil coned weyer ibm dec mobil tex cpl _type_ $ _rhs_; cards; exp_return .0176 .0288 .0148 .021 .0092 .0103 .0182 .0172 .0121 .0146 max . beta .5309 1.048 .1383 .102 .7231 .3954 .7157 .6856 .5786 .2068 eq .7 sum_wts 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 eq 1.0 available .3333 .3333 .3333 .333 .3333 .3333 .3333 .3333 .3333 .3333 upperbd . available .05 .05 .05 .05 .05 .05 .05 .05 .05 .05 lowerbd . ; proc lp data=weight2 primalout=lp_out2; title2 'More Restricted Portfolio Weights'; run; quit; /* Example Code Found on Page 141 */ /* WEIGHT2 Data Set Created in Example Code on Page 138 */ proc lp data=weight2 primalin=lp_out2 rangeprice rangerhs; title2 'Sensitivity Analyses'; run; quit; /* Example Code Found on Page 143 */ /* WEIGHT2 Data Set Created in Example Code on Page 138 */ data weight3; set weight2; if _id_ = 'beta' then _type_ = 'le'; run; proc lp data=weight3 primalout=lp_out3; run; quit; /* Example Code Found on Page 144 */ /* LP_OUT3 Data Set Created in Example Code on Page 143 */ data lp_out3a; set lp_out3; if _n_ > 10 then delete; amount=_value_*100000; rename _var_ = asset; run; proc print data=lp_out3a; var asset amount; title 'Linear Programming'; title2 'Amount to Invest in Each Asset'; run; /* Example Code Found on Page 146 */ data weight4; input _id_ $10. gerber tandy genmil coned weyer ibm dec mobil tex cpl _type_ $ _rhs_; cards; exp_return .0176 .0288 .0148 .021 .0092 .0103 .0182 .0172 .0121 .0146 max . beta .5309 1.048 .1383 .102 .7231 .3954 .7157 .6856 .5786 .2068 le 10 lots 4138 4250 4313 4713 3775 12000 10475 4013 3588 3863 le 100000 upper 7 7 7 7 7 4 4 7 7 7 upperbd . lower 1 1 1 1 1 1 1 1 1 1 lowerbd . integer 1 2 3 4 5 6 7 8 9 10 integer . ; proc lp data=weight4 imaxit=200 primalout=lp_out4 dualout=d_out; run; /* Example Code Found on Page 147 */ /* LP_OUT4 Data Set Created in Example Code on Page 146 */ data lp_out4a(keep= _var_ _value_ rename= _var_=name); set lp_out4; if _n_ > 10 then delete; run; proc print data=lp_out4a; title 'Integer Programming'; title2 'Number of 100 Share Lots to Buy'; run; /* Example Code Found on Page 148 */ /* D_OUT Data Set Created in Example Code on Page 146 */ proc print data=d_out; title 'Linear Programming'; title2 'Return, Risk, and Size of Portfolio'; run; /* Example Code Found on Page 149 */ /* WEIGHT4 Data Set Created in Example Code on Page 146 */ proc transpose data=weight4 out=wt1; run; data wt2(drop=col4 col5 col6); set wt1; if _n_ > 10 then delete; rename _name_=name col1=return col2=beta col3=lots; run; proc print data=wt2; title 'Integer Programming'; title2 'Transposed and Tailored Input Data Set'; run; /* Example Code Found on Page 150 */ /* LP_OUT4A Data Set Created in Example Code on Page 147 */ /* WT2 Data Set Created in Example Code on Page 149 */ data wt3; merge lp_out4a wt2; run; proc print data=wt3; title 'Integer Programming'; title2 'Merged Data Set'; run; /* Example Code Found on Page 151 */ /* WT3 Data Set Created in Example Code on Page 150 */ data wt4; set wt3; amt=99719; fraction=_value_*lots/amt; risk=fraction*beta; exp_ret=fraction*return; run; proc means data=wt4 sum; var risk exp_ret; title2 'Comparable Measures of Risk and Return'; run; /* Example Code Found on Pages 152-153 */ data weight5; input _id_ $10. gerber1 gerber2 tandy1 tandy2 genmil1 genmil2 coned1 coned2 weyer1 weyer2 / ibm1 ibm2 dec1 dec2 mobil1 mobil2 tex1 tex2 cpl1 cpl2 _type_ $ _rhs_; cards; exp_return .0176 -.0176 .0288 -.0288 .0148 -.0148 .021 -.021 .0092 -.0092 .0103 -.0103 .0182 -.0182 .0172 -.0172 .0121 -.0121 .0146 -.0146 max . beta .5309 -.5309 1.048 -1.048 .1383 -.1383 .102 -.102 .7231 -.7231 .3954 -.3954 .7157 -.7157 .6856 -.6856 .5786 -.5786 .2068 -.2068 le 1.0 sum_wts 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eq 1 available 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 upperbd . ; proc lp data=weight5 primalout=lp_out5; run; quit; data lp_out5a; set lp_out5; if _n_ > 20 then delete; if _value_ = 0 then delete; amount=_value_*100000; rename _var_ = asset; run; proc print data=lp_out5a; var asset amount; title 'Linear Programming'; title2 'Amount to Invest in Each Stock'; run; /* Example Code Found on Pages 153-154 */ /* WEIGHT5 Data Set Created in Example Code on Page 152-153 */ data weight5b; set weight5; if _id_ = 'beta' then _rhs_ = .75; run; proc lp data=weight5b primalout=lp_out5b; run; quit; /* Example Code Found on Pages 155 */ data weight6; input _id_ $10. gerber1 gerber2 tandy1 tandy2 genmil1 genmil2 coned1 coned2 weyer1 weyer2 / ibm1 ibm2 dec1 dec2 mobil1 mobil2 tex1 tex2 cpl1 cpl2 _type_ $ _rhs_; cards; exp_return .0176 -.0176 .0288 -.0288 .0148 -.0148 .021 -.021 .0092 -.0092 .0103 -.0103 .0182 -.0182 .0172 -.0172 .0121 -.0121 .0146 -.0146 max . beta .5309 -.5309 1.048 -1.048 .1383 -.1383 .102 -.102 .7231 -.7231 .3954 -.3954 .7157 -.7157 .6856 -.6856 .5786 -.5786 .2068 -.2068 le 1.0 sum_wts 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 eq 1 upper .25 .1 .25 .1 .25 .1 .25 .1 .25 .1 .25 .1 .25 .1 .25 .1 .25 .1 .25 .1 upperbd . ; proc lp data=weight6 primalout=lp_out6; run; quit; data lp_out6a; set lp_out6; if _n_ > 20 then delete; if _value_ = 0 then delete; amount=_value_*100000; rename _var_ = asset; run; proc print data=lp_out6a; var asset amount; title 'Linear Programming'; title2 'Amount to Invest in Each Stock'; run; /* Chapter 6 */ /* Example Code Found on Page 163 */ /* RETURN3 Data Set Created in Example Code on Pages 109-112 */ proc corr data=return3 cov outp=cov_out1 nosimple; var coned mobil tex; title 'Markowitz Model'; run; proc print data=cov_out1; title2 'Covariances, Means, and Correlations'; run; /* Example Code Found on Page 164 */ /* COV_OUT1 Data Set Created in Example Code on Page 163 */ data cov_out2(drop=_name_); set cov_out1; if _type_ ne 'MEAN' then delete; do x = 0 to 1 by .05; output; end; label x='Portfolio Weight'; run; data mean1; set cov_out2; pfol_m1=x*coned+(1-x)*mobil; pfol_m2=x*coned+(1-x)*tex; pfol_m3=x*mobil+(1-x)*tex; run; proc print data=mean1; title 'Markowitz Model'; title2 '2-Stock Portfolio Returns'; run; /* Example Code Found on Page 165 */ /* MEAN1 Data Set Created in Example Code on Page 164 */ proc plot data=mean1 vpct=150; plot pfol_m1*x='1' pfol_m2*x='2' pfol_m3*x='3' / overlay; title2 'Portfolio Return versus Portfolio Weight'; run; /* Example Code Found on Pages 166-167 */ /* MEAN1 Data Set Created in Example Code on Page 164 */ data risk1; set mean1; pfol_v1=x**2*.0025956+(1-x)**2*.0060380-2*x*(1-x)*.0000940; pfol_v2=x**2*.0025956+(1-x)**2*.0057176-2*x*(1-x)*.0004572; pfol_v3=x**2*.0060380+(1-x)**2*.0057176+2*x*(1-x)*.0041150; array pfol_v(3) pfol_v1-pfol_v3; array pfol_r(3) pfol_r1-pfol_r3; do i=1 to 3; pfol_r(i)=sqrt(pfol_v(i)); end; run; proc print data=risk1; var x pfol_v1 pfol_r1-pfol_r3; title2 '2-Stock Portfolio Risk Levels'; run; /* Example Code Found on Page 168 */ /* RISK1 Data Set Created in Example Code on Pages 166-167 */ proc plot data=risk1 vpct=175; plot pfol_r1*x='1' pfol_r2*x='2' pfol_r3*x='3' / overlay; title2 'Portfolio Risk versus Portfolio Weight'; run; /* Example Code Found on Page 169 */ /* RISK1 Data Set Created in Example Code on Pages 166-167 */ proc plot data=risk1 vpct=200; plot pfol_m1*pfol_r1='1' pfol_m2*pfol_r2='2' pfol_m3*pfol_r3='3' / overlay vaxis=.012 to .021 by .003; title2 'Portfolio Return versus Portfolio Risk'; run; /* Example Code Found on Pages 170-171 */ /* RISK1 Data Set Created in Example Code on Pages 166-167 */ data risk2(drop=pfol_m3 pfol_r3); set risk1; if x < .61 then delete; run; proc plot data=risk2 vpct=225; plot pfol_m1*pfol_r1='*' $ x pfol_m2*pfol_r2='@' $ x / overlay vaxis=.0175 to .0214 by .0003; title2 'Return versus Risk'; title3 'Selected Portfolios'; run; /* Example Code Found on Page 173 */ proc nlp outest=nlp_out1; min risk; parms x1=.5, x2=.5; var_p=x1*x1*.0025956+x2*x2*.0057176-2*x1*x2*.0004572; risk=var_p**.5; bounds 0 <= x1-x2 <= 1; lincon 1=x1+x2; title 'Markowitz Model'; title2 'Quadratic Programming Portfolio Weights'; title3; run; /* Example Code Found on Page 177 */ /* NLP_OUT1 Data Set Created in Example Code on Page 173 */ proc print data=nlp_out1; title2 'NLP_OUT1 Data Set'; run; /* Example Code Found on Page 178 */ data in_nlp1(type=est); input _type_ $8. coned tex _rhs_; cards; parms .5 .5 . lowerbd 0 0 . upperbd 1 1 . eq 1 1 1 ; proc nlp inest=in_nlp1; min risk; parms coned tex; var_p=coned*coned*.0025956+tex*tex*.0057176-2*coned*tex*.0004572; risk=var_p**.5; run; /* Example Code Found on Page 180 */ data in_nlp2(type=est); input _type_ $8. coned tex _rhs_; cards; parms .5 .5 . lowerbd 0 0 . upperbd 1 1 . eq 1 1 1 ge .021 .0121 .0195 ; proc nlp inest=in_nlp2 outest=nlp_out2 noprint; min risk; parms coned tex; var_p=coned*coned*.0025956+tex*tex*.0057176-2*coned*tex*.0004572; risk=var_p**.5; run; proc print data=nlp_out2; title2 'Quadratic Programming Portfolio Weights'; title3 'Expected Return Must Be 1.95% or More'; run; /* Example Code Found on Page 182 */ /* NLP_OUT2 Data Set Created in Example Code on Page 180 */ data amt_out2(drop=_TECH_ _NAME_); set nlp_out2; if _TYPE_ ne 'PARMS' then delete; coned_a=round(coned*100000, .01); tex_a=round(tex*100000, .01); total=sum(of coned_a tex_a); run; proc print data=amt_out2; var coned_a tex_a total; title2 'Amount to Invest in Each Stock'; title3; run; /* Example Code Found on Pages 182-183 */ proc nlp outest=nlp_out4 noprint; parms x1 - x10; var= x1*x1*.0065845 + x2*x2*.0161666 + x3*x3*.0034068 + x4*x4*.0025956 + x5*x5*.0061889 + x6*x6*.0030980 + x7*x7*.0081904 + x8*x8*.0060380 + x9*x9*.0057176 + x10*x10*.0028676 + 2*x1*x2*.0012481 + 2*x1*x3*.0008390 + 2*x1*x4*.0008552 + 2*x1*x5*.0014933 + 2*x1*x6*.0011241 + 2*x1*x7*.0008087 + 2*x1*x8*.0016392 + 2*x1*x9*.0010154 + 2*x1*x10*.0007377 + 2*x2*x3*.0024433 + 2*x2*x4*.0006034 + 2*x2*x5*.0043589 + 2*x2*x6*.0021623 + 2*x2*x7*.0055136 + 2*x2*x8*.0018761 + 2*x2*x9*.0019255 + 2*x2*x10*.0008840 + 2*x3*x4*.0011501 + 2*x3*x5*.0013081 + 2*x3*x6*.0002182 + 2*x3*x7*.0005988 - 2*x3*x8*.0004289 - 2*x3*x9*.0008492 + 2*x3*x10*.0011713 + 2*x4*x5*.0006618 + 2*x4*x6*.0002583 + 2*x4*x7*.0003856 - 2*x4*x8*.0000940 - 2*x4*x9*.0004572 + 2*x4*x10*.0017717 + 2*x5*x6*.0017847 + 2*x5*x7*.0033916 + 2*x5*x8*.0018391 + 2*x5*x9*.0009703 + 2*x5*x10*.0010631 + 2*x6*x7*.0017977 + 2*x6*x8*.0009574 + 2*x6*x9*.0007195 + 2*x6*x10*.0002032 + 2*x7*x8*.0023587 + 2*x7*x9*.0014764 + 2*x7*x10*.0008061 + 2*x8*x9*.0041150 + 2*x8*x10*.0000495 - 2*x9*x10*.0001139; risk=sqrt(var); min risk; bounds 0 <= x1-x10 <= 1; lincon 1=x1+x2+x3+x4+x5+x6+x7+x8+x9+x10, .019 <= .0176*x1+.0288*x2+.0148*x3+.0210*x4+.0092*x5 +.0103*x6+.0182*x7+.0172*x8+.0121*x9+.0146*x10; run; proc print data=nlp_out4 (obs=10); title2 'Quadratic Programming Portfolio Weights'; title3 'Ten-Stock Example'; run; /* Example Code Found on Pages 184-185 */ /* NLP_OUT4 Data Set Created in Example Code on Pages 182-183 */ data amt_out3; set nlp_out4; if _TYPE_ ne 'PARMS' then delete; array xa(10) x1-x10; array a(10) a1-a10; do i=1 to 10; a(i)=round(xa(i)*100000, .001); end; total=sum(of a1-a10); run; data amt_out4; set amt_out3; rename a1=gerber a2=tandy a3=genmil a4=coned a5=weyer a6=ibm a7=dec a8=mobil a9=tex a10=cpl; run; proc print data=amt_out4; var gerber tandy genmil coned weyer ibm dec mobil tex cpl total; title2 'Amount to Invest in Each Stock'; title3; run; /* Example Code Found on Pages 190-191 */ data plot1; input return obj_fun @@; risk=sqrt(2*obj_fun); cards; .0288 .00808331 .0280 .00657942 .0270 .00495925 .0260 .00362764 .0250 .00258457 .0240 .00183006 .0230 .00135805 .0220 .00106108 .0210 .00088853 .0200 .00077936 .0190 .00069069 .0180 .00061873 .0170 .00056347 .0160 .00052555 .0150 .00050807 .0140 .00050699 .007161 0.0 ; proc plot data=plot1 vpct=225; plot return*risk='*' $ return; title2 'The Capital Market Line'; run; /* Example Code Found on Page 192 */ /* PLOT1 Data Set Created in Example Code on Pages 190-191 */ proc plot data=plot1 vpct=225; plot return*risk='*' $ return / vref=.020 href=.03948 vaxis=.007 to .029 by .002; run; /* Example Code Found on Pages 193-194 */ proc nlp outest=nlp_out8 noprint; parms x1 - x10; var= x1*x1*.0065845 + x2*x2*.0161666 + x3*x3*.0034068 + x4*x4*.0025956 + x5*x5*.0061889 + x6*x6*.0030980 + x7*x7*.0081904 + x8*x8*.0060380 + x9*x9*.0057176 + x10*x10*.0028676 + 2*x1*x2*.0012481 + 2*x1*x3*.0008390 + 2*x1*x4*.0008552 + 2*x1*x5*.0014933 + 2*x1*x6*.0011241 + 2*x1*x7*.0008087 + 2*x1*x8*.0016392 + 2*x1*x9*.0010154 + 2*x1*x10*.0007377 + 2*x2*x3*.0024433 + 2*x2*x4*.0006034 + 2*x2*x5*.0043589 + 2*x2*x6*.0021623 + 2*x2*x7*.0055136 + 2*x2*x8*.0018761 + 2*x2*x9*.0019255 + 2*x2*x10*.0008840 + 2*x3*x4*.0011501 + 2*x3*x5*.0013081 + 2*x3*x6*.0002182 + 2*x3*x7*.0005988 - 2*x3*x8*.0004289 - 2*x3*x9*.0008492 + 2*x3*x10*.0011713 + 2*x4*x5*.0006618 + 2*x4*x6*.0002583 + 2*x4*x7*.0003856 - 2*x4*x8*.0000940 - 2*x4*x9*.0004572 + 2*x4*x10*.0017717 + 2*x5*x6*.0017847 + 2*x5*x7*.0033916 + 2*x5*x8*.0018391 + 2*x5*x9*.0009703 + 2*x5*x10*.0010631 + 2*x6*x7*.0017977 + 2*x6*x8*.0009574 + 2*x6*x9*.0007195 + 2*x6*x10*.0002032 + 2*x7*x8*.0023587 + 2*x7*x9*.0014764 + 2*x7*x10*.0008061 + 2*x8*x9*.0041150 + 2*x8*x10*.0000495 - 2*x9*x10*.0001139; risk=sqrt(var); r_f=.007161; num= .0176*x1+.0288*x2+.0148*x3+.0210*x4+.0092*x5+.0103*x6 +.0182*x7+.0172*x8+.0121*x9+.0146*x10-r_f; obj=num/risk; max obj; bounds 0 <= x1-x10 <= 1; lincon 1=x1+x2+x3+x4+x5+x6+x7+x8+x9+x10; run; /* Example Code Found on Page 194 */ /* NLP_OUT8 Data Set Created in Example Code on Pages 193-194 */ data amt_out5; set nlp_out8; if _TYPE_ ne 'PARMS' then delete; run; proc print data=amt_out5; var x1-x10; title 'Markowitz Model'; title2 'Tangential Efficient Portfolio Weights'; run; /* Chapter 7 */ /* Example Code Found on Pages 199-200 */ /* Tailoring the LP_OUT1 Data Set from Output 5.2 */ /* LP_OUT1 Data Set Created in Example Code on Page 135 */ data lp_out1a(keep= _var_ _value_ rename= _var_=name); set lp_out1; if _n_ > 10 then delete; run; /* Transposing the Data Set LP_OUT1A */ proc transpose data=lp_out1a out=lp_out1b(drop=_name_ _label_ rename=(col1=x1 col2=x2 col3=x3 col4=x4 col5=x5 col6=x6 col7=x7 col8=x8 col9=x9 col10=x10)); var _value_; run; /* Transposing the Data Set LP_OUT3A from Output 5.6 */ /* LP_OUT3A Data Set Created in Example Code on Page 144 */ proc transpose data=lp_out3a out=lp_out3b(drop=_name_ _label_ rename=(col1=x1 col2=x2 col3=x3 col4=x4 col5=x5 col6=x6 col7=x7 col8=x8 col9=x9 col10=x10)); var _value_; run; /* Transposing the Data Set WT4 from Output 5.11 */ /* WT4 Data Set Created in Example Code on Page 151 */ proc transpose data=wt4 out=wt4a(drop=_name_ rename=(col1=x1 col2=x2 col3=x3 col4=x4 col5=x5 col6=x6 col7=x7 col8=x8 col9=x9 col10=x10)); var fraction; run; /* Tailoring the LP_OUT4 Data Set from Output 6.13 */ /* NLP_OUT4 Data Set Created in Example Code on Pages 182-183 */ data amtout3a(drop=_tech_ _type_ _name_ _rhs_ _iter_); set nlp_out4; if _TYPE_ ne 'PARMS' then delete; run; /* Tailoring the LP_OUT8 Data Set from Output 6.17 */ /* NLP_OUT8 Data Set Created in Example Code on Pages 193-194 */ data amtout5a(drop=_tech_ _type_ _name_ _rhs_ _iter_); set nlp_out8; if _TYPE_ ne 'PARMS' then delete; run; /* Merging the Tailored and Transposed Data Sets */ data p_folio1; set lp_out1b lp_out3b wt4a amtout3a amtout5a; run; /* Printing the P_FOLIO1 Data Set */ proc print data=p_folio1; title 'Portfolio Evaluation'; title2 'Portfolio Weights'; run; /* Example Code Found on Page 201 */ /* RETURN3 Data Set Created in Example Code on Pages 109-112 */ proc transpose data=return3 out=return3a; var r_m r_f; run; data return3b; set return3a; r=mean(of col1-col108); if _n_ = 1 then name = 'Market '; if _n_ = 2 then name = 'Risk Free'; run; proc print data=return3b; var name r; title2 'Expected Returns'; run; /* Example Code Found on Page 202 */ /* P_FOLIO1 Data Set Created in Example Code on Pages 199-200 */ data p_folio2; set p_folio1; r= .0176*x1+.0288*x2+.0148*x3+.021*x4+.0092*x5+.0103*x6 +.0182*x7+.0172*x8+.0121*x9+.0146*x10; if _n_ = 1 then name = 'Ex_5.2 '; if _n_ = 2 then name = 'Ex_5.5 '; if _n_ = 3 then name = 'Ex_5.7 '; if _n_ = 4 then name = 'Ex_6.13 '; if _n_ = 5 then name = 'Ex_6.17 '; run; proc print data=p_folio2; var name r; title2 'Expected Portfolio Returns'; run; /* Example Code Found on Page 203 */ /* P_FOLIO2 Data Set Created in Example Code on Page 202 */ /* RETURN3B Data Set Created in Example Code on Page 201 */ data p_folio3; set p_folio2 return3b; run; proc print data=p_folio3; var name r; title2 'Expected Portfolio Returns'; run; /* Example Code Found on Pages 204-205 */ data return4; input r_m r_f gerber tandy genmil coned weyer ibm dec mobil tex cpl; retain date '01dec86'd; date=intnx('month',date,1); format date monyy.; r_mkt=r_m-r_f; cards; .148 .00454 .057 .130 .123 .040 .270 .073 .385 .093 .049 .102 .065 .00437 .019 .174 .049 -.067 .094 .092 .056 -.022 -.080 -.060 .037 .00423 .040 -.118 .010 -.050 .089 .076 .061 .124 .103 .013 -.025 .00207 -.063 -.119 -.104 .020 -.027 .067 .055 -.007 -.094 -.039 .004 .00438 .138 -.026 .190 -.012 -.107 .006 -.082 -.003 .114 -.090 .038 .00402 .005 .045 .030 .059 .026 .016 .041 .091 .073 .088 .055 .00455 .232 .087 .036 -.039 .021 -.009 .000 .032 .142 -.035 .015 .00460 -.113 .027 .022 .043 .081 .053 .157 .030 -.076 .021 -.015 .00520 -.061 .088 -.009 -.006 -.054 -.105 .001 -.082 -.053 -.014 -.260 .00358 -.288 -.246 -.148 -.017 -.271 -.187 -.281 -.178 -.194 -.040 -.070 .00288 -.085 -.190 -.102 -.012 -.066 -.087 -.127 -.150 -.031 -.019 .073 .00277 .070 .040 .128 -.006 .103 .043 .134 .159 .178 .023 ; proc transpose data=return4 out=return4a; var r_m r_f; run; data return4b; set return4a; t=12; array col(12) col1-col12; array ss(12) s1-s12; do i=1 to 12; ss(i) = col(i) + 1; end; wealth=(s1*s2*s3*s4*s5*s6*s7*s8*s9*s10*s11*s12); gm=((wealth)**(1/t))-1; gm_pct=gm*100; am=mean(of col1-col12); am_pct=am*100; if _n_ = 1 then name = 'Market '; if _n_ = 2 then name = 'Risk Free'; run; proc print data=return4b; var name gm gm_pct am am_pct wealth; title2 'Return Measures'; title3 'Market Portfolio and Risk-Free Asset'; run; /* Example Code Found on Pages 207-208 */ /* P_FOLIO1 Data Set Created in Example Code on Pages 199-200 */ /* RETURN4 Data Set Created in Example Code on Pages 204-205 */ proc iml; use p_folio1; read all var _num_ into xx; xt=t(xx); use return4; read all var {gerber tandy genmil coned weyer ibm dec mobil tex cpl} into rr; rx=rr*xt; rxt=t(rx); varname1='r_act1' : 'r_act5'; create actual1 from rx [colname= varname1]; append from rx; close actual1; varname2='t1' : 't12'; create actual2 from rxt [colname= varname2]; append from rxt; close actual2; quit; proc print data=actual2; title2 'ACTUAL2, Weights Times Stock Returns'; run; /* Example Code Found on Page 209 */ /* ACTUAL2 Data Set Created in Example Code on Pages 207-208 */ data actual3; set actual2; t=12; array tt(12) t1-t12; array ss(12) s1-s12; do i=1 to 12; ss(i) = tt(i) + 1; end; wealth=(s1*s2*s3*s4*s5*s6*s7*s8*s9*s10*s11*s12); gm=((wealth)**(1/t))-1; gm_pct=gm*100; am=mean(of t1-t12); am_pct=am*100; if _n_ = 1 then name = 'Ex_5.2 '; if _n_ = 2 then name = 'Ex_5.5 '; if _n_ = 3 then name = 'Ex_5.7 '; if _n_ = 4 then name = 'Ex_6.13 '; if _n_ = 5 then name = 'Ex_6.17 '; run; proc print data=actual3; var name gm gm_pct am am_pct wealth; title2 'Actual Portfolio Returns'; run; /* Example Code Found on Page 210 */ /* ACTUAL3 Data Set Created in Example Code on Page 209 */ /* RETURN4B Data Set Created in Example Code on Pages 204-205 */ data actual4; set actual3 return4b; run; proc print data=actual4; var name gm gm_pct am am_pct wealth; run; /* Example Code Found on Pages 211-212 */ /* RETURN4 Data Set Created in Example Code on Pages 204-205 */ /* ACTUAL1 Data Set Created in Example Code on Pages 207-208 */ data return4c; merge return4 actual1; array r_act(5) r_act1-r_act5; array rp(5) rp1-rp5; do i=1 to 5; rp(i) = r_act(i)-r_f; end; run; proc reg data=return4c outest=capmest2; model rp1=r_mkt; model rp2=r_mkt; model rp3=r_mkt; model rp4=r_mkt; model rp5=r_mkt; run; /* Example Code Found on Page 213 */ /* CAPMEST2 Data Set Created in Example Code on Pages 211-212 */ /* ACTUAL4 Data Set Created in Example Code on Page 210 */ data return4d; merge capmest2(rename=(r_mkt=beta)) actual4; r_f=.0039325; if _n_ = 6 then beta=1; treynor=(am-r_f)/beta; run; proc print data=return4d; var name am r_f beta treynor; title2 'Treynor Index Values'; title3; run; /* Example Code Found on Pages 214-215 */ /* RETURN4 Data Set Created in Example Code on Pages 204-205 */ /* RETURN4C Data Set Created in Example Code on Pages 211-212 */ data return4e; merge return4 return4c; run; proc transpose data=return4e out=return4f; var rp1-rp5 r_mkt; run; data return4g; set return4f; mean = mean(of col1-col12); std = std(of col1-col12); sharpe=mean/std; if _n_ = 1 then name = 'Ex_5.2 '; if _n_ = 2 then name = 'Ex_5.5 '; if _n_ = 3 then name = 'Ex_5.7 '; if _n_ = 4 then name = 'Ex_6.14'; if _n_ = 5 then name = 'Ex_6.17'; if _n_ = 6 then name = 'Market '; run; proc print data=return4g; var name mean std sharpe; title2 'Sharpe Index Values'; run; /* Chapter 8 */ /* Example Code Found on Pages 220-221 */ data binom1; price=50; price_h=60; price_l=40; sp=55; t=1; r=.10; p_down=(price_l-price)/price; p_up=(price_h-price)/price; p=(r-p_down)/(p_up-p_down); mean=p*p_up+(1-p)*p_down; var=p*((p_up-mean)**2)+(1-p)*((p_down-mean)**2); s=sqrt(var); exponent=s*sqrt(t); up=exp(exponent); down=1/up; up_per=up-1; down_per=down-1; if price_hsp then gain=price_h-sp; exp_ret=gain*p; pv_call=exp_ret/(1+r); run; proc print data=binom1; title 'Option Pricing'; title2 'Binomial Model'; title3 'Call Option'; run; /* Example Code Found on Page 222 */ data binom2; input price price_h price_l sp @@; r=.10; t=1; p_down=(price_l-price)/price; p_up=(price_h-price)/price; p=(r-p_down)/(p_up-p_down); mean=p*p_up+(1-p)*p_down; var=p*((p_up-mean)**2)+(1-p)*((p_down-mean)**2); s=sqrt(var); exponent=s*sqrt(t); up=exp(exponent); down=1/up; up_per=up-1; down_per=down-1; if price_hsp then gain=price_h-sp; exp_ret=gain*p; pv_call=exp_ret/(1+r); cards; 50 60 40 52.5 50 60 40 55 50 60 40 57.5 50 65 35 52.5 50 65 35 55 50 65 35 57.5 50 70 30 52.5 50 70 30 55 50 70 30 57.5 ; proc print data=binom2; var sp price_h price_l p exp_ret pv_call; title3 'Call Options'; run; /* Example Code Found on Page 223 */ /* BINOM1 Data Set Created in Example Code on Pages 220-221 */ data binom1; set binom1; pv_sp=sp/(1+r); if spsp then gain=price_h-sp; exp_ret=gain*p; pv_call=exp_ret/(1+r); pv_sp=sp/(1+r); if sp