FOCUS AREAS

SAS/ETS Examples

Fitting a Capital Asset Pricing Model


Contents | Back to Example

SAS Program

/* Fitting a Capital Asset Pricing Model */

data tandy;
  input r_m r_f tandy @@;
  r_tandy = tandy - r_f;
  r_mkt = r_m -r_f;
  label r_m='Market Rate of Return'
        r_f='Risk-Free Rate of Return'
        tandy='Rate of Return for Tandy Corporation'
        r_tandy='Risk Premium for Tandy Corporation'
        r_mkt='Risk Premium for Market';
datalines;
-.045 .00487 -.075
 .063 .00491  .055
 .071 .00528  .194
-.189 .00685 -.206
 .058 .00761 -.046
 .026 .00764 -.094
-.013 .00728  .006
-.097 .00913 -.037
 .124 .00883  .032
 .080 .00753 -.038
 .065 .00602  .446
 .006 .00895 -.015
-.014 .01092 -.139
-.008 .01084  .092
-.033 .01154  .032
 .062 .01003  .241
-.079 .00949  .059
 .041 .00972  .053
-.006 .00714  .050
 .136 .00620  .454
 .065 .00646  .091
 .097 .00652  .084
-.017 .00714 -.123
-.082 .00678 -.058
-.029 .00712 -.190
-.003 .00741  .120
-.058 .00771  .029
-.035 .00688 -.096
 .097 .00606  .170
-.010 .00601 -.133
 .010 .00494 -.004
 .067 .00513  .176
 .079 .00607  .222
 .084 .00719  .086
 .011 .00761 -.135
 .014 .00772 -.148
 .095 .00789  .250
 .116 .00819  .170
 .112 .01073  .143
 .062 .00630  .256
 .025 .00731  .167
 .092 .01137  .212
-.009 .01096  .082
 .064 .01255  .136
-.031 .01169 -.063
 .069 .00816 -.037
-.101 .00946 -.101
 .003 .00908 -.163
 .122 .00503  .017
 .049 .00614  .273
 .028 .00599  .032
 .080 .00649 -.010
-.034 .00668 -.048
 .066 .00683  .082
-.030 .00672 -.100
-.058 .00627 -.231
 .146 .00852  .079
-.019 .00602  .027
 .012 .00586  .119
 .019 .00512  .091
 .050 .00526  .124
 .007 .00527 -.014
 .002 .00645 -.100
 .015 .00690  .085
 .123 .00769  .122
 .075 .00715  .096
 .039 .00802 -.005
 .086 .00747  .037
-.243 .01181 -.105
 .086 .00503  .041
 .015 .00860  .157
-.056 .00977  .022
 .067 .01025  .299
-.003 .01128 -.167
-.164 .01054 -.008
-.039 .00740 -.046
-.028 .01067 -.051
-.078 .00914  .023
 .008 .00563 -.026
 .014 .00648 -.042
 .043 .00686 -.004
 .048 .00673 -.168
 .000 .00702 -.083
-.012 .00693  .095
 .003 .00763 -.008
 .005 .00748 -.037
 .000 .00830 -.100
-.001 .00612  .005
 .008 .00650  .094
-.003 .00536  .087
 .012 .00562 -.119
 .026 .00577  .098
-.009 .00548 -.040
-.009 .00444 -.058
-.076 .00458 -.078
 .018 .00418  .242
 .148 .00454  .130
-.025 .00207 -.119
 .055 .00455  .087
-.260 .00358 -.246
 .005 .00545  .063
 .059 .00540  .021
 .049 .00523  .096
 .049 .00469  .094
 .049 .00343  .018
 .000 .00420  .094
 .065 .00437  .174
 .004 .00438 -.026
 .015 .00460  .027
-.070 .00288 -.190
-.055 .00571 -.011
 .013 .00479  .098
 .048 .00508 -.047
 .004 .00478 -.092
-.047 .00416 -.108
-.005 .00382 -.023
 .037 .00423 -.118
 .038 .00402  .045
-.015 .00520  .088
 .073 .00277  .040
;

proc gplot data=tandy;
  plot r_tandy * r_mkt / haxis=axis1 hminor=4 cframe=ligr
                         vaxis=axis2 vminor=4;
  symbol1 c=blue v=star;
  axis1 order=(-0.3 to 0.2 by 0.1);
  axis2 label=(angle=90 'Tandy Corp. Risk Premium')
        order=(-0.4 to 0.6 by 0.2);
  title 'TANDY Corporation CAPM Example';
  title2'Plot of Risk Premiums';
  title3'Tandy Corporation versus the Market';
run;


proc autoreg data=tandy;
  model r_tandy = r_mkt / dwprob;
  test r_mkt = 1;
  output out=tandyout p=p r=r ucl=u lcl=l alphacli=.10;
  title2;
  title3;
run;


proc gplot data=tandyout;
  plot r * r_mkt / haxis=axis1 hminor=4 cframe=ligr
                   vaxis=axis2 vminor=4
                   vref=0.0;
  symbol1 c=green v=star;
  axis1 order=(-0.3 to 0.2 by 0.1);
  axis2 label=(angle=90 'Tandy Corp. Risk Premium')
        order=(-0.3 to 0.4 by 0.1);
  title 'TANDY Corporation CAPM Example';
  title2'OLS Residuals versus Market Risk Premium';
run;


proc sort data=tandyout;
  by r_mkt;
run;

data regdata(keep=y_value pt_type r_mkt);
  set tandyout;
  label pt_type='Observation Type';
  array regvar{4} r_tandy p 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 hminor=4 cframe=ligr
                               vaxis=axis2 vminor=4;
  symbol1 c=black v=star;
  symbol2 c=blue i=join l=2;
  symbol3 c=green i=join l=1;
  symbol4 c=red i=join l=2;
  axis1 order=(-.3 to .15 by .05);
  axis2 label=(angle=90 'Tandy Corp. Risk Premium')
        order=(-.5 to .5 by .25);
  title1 "Actual and Predicted Values";
  title2 "with Upper and Lower Confidence Limits";
run;
quit;