Help using Base SAS procedures

Portfolio Formation and Holding Period (1,3,6,12,24months) with Analysts' Forecast Revision

Occasional Contributor
Posts: 6

Portfolio Formation and Holding Period (1,3,6,12,24months) with Analysts' Forecast Revision

Hi all,

I am using IBES analysts forecast revision and CRSP for stock prices.

I am quite new to SAS and I have been trying to figure out how to form portfolio of analysts forecast revision to examine stock price drift for 1month, 3months, 6months, 12months and 24months. What I am trying to achieve is to hold stocks at time t, and buy or sell stocks according to the degree of analysts' forecast revision (1 = lowest (SELL) and 5 = highest (BUY)) at time t, and find the cumulative returns for 1,3,6,12 and 24 months of the stocks bought or sold at time t. (Without changing the portfolio). In other words, stocks will stay in the portfolio at time t and I will buy or sell according to the ranking of analysts' forecast revision.

HOWEVER, I only can manage to find stock returns at time t to analysts' forecast revision portfolio at time t, and I cant get the codes for the cumulative returns.

Below are my codes:

/* Step 1. Specifying Options */

%let J=6; /* Formation Period Length: J can be between 3 to 12 months - can be adjusted */

%let K=6; /* Holding   Period Length: K can be between 3 to 12 months - can be adjusted*/

%let begdate=01JAN1994;

%let enddate=31DEC2014;


/* Step 2. Assign Ranks to the Next 6 (K) Months After Portfolio Formation */

/* Forecast_revision_portfolio is the portfolio rank variable taking values between 1 and 5: */

/*          1 - the lowest  momentum group: Losers   */

/*         5 - the highest momentum group: Winners  */

data getr_2 ;

set getr_2;

HDATE1 = intnx("MONTH",date, 0,"B")-1;

HDATE2 = intnx("MONTH",date,&k-1,"E");

format HDATE1 HDATE2 monyy.;

label HDATE1= "First Holding Date";

label HDATE2= "Last Holding Date";


/* Portfolio returns are average monthly returns rebalanced monthly */

proc sql;

    create table getr_3

    as select distinct*

    from getr_2 as a, recency as b

    where a.cusip=b.cusip

    and a.HDATE1<<=a.HDATE2

order by cusip, date;


/* Step 4. Calculate Equally-Weighted Average Monthly Returns */

proc sort data=getr_3 nodupkey; by cusip date analys; run;

proc sort data=getr_3; by date forecast_revision_rank HDATE1;run;

/* Calculate Equally-Weighted returns across portfolio stocks */

/* Every date, each MOM group has J portfolios identified by formation date */

proc means data = getr_3 noprint;

  by date forecast_revision_rank HDATE1;

    var mean_returns;

    output out = umd3 mean=mean_returns;


/* Portfolio average monthly returns */

proc sort data=umd3; by date Forecast_revision_rank;

    where year(date) >= year("&begdate"d);


/* Create one return series per MOM group every month */

proc means data = umd3 noprint;

  by date forecast_revision_rank;

    var mean_returns;

    output out = ewretdat mean= ewret std = ewretstd;


proc sort data=ewretdat; by forecast_revision_rank ; run;

Title "Table 1: Returns of Analysts' Forecast Revision Portfolios";

Title2 "Portfolios based on 6 months lagged return and held for 6 months";

proc means data=ewretdat n mean t probt;

  class Forecast_revision_rank;

    var ewret;


/* Step 5. Calculate Long-Short Portfolio Returns */

proc sort data=ewretdat; by date Forecast_revision_rank; run;

proc transpose data=ewretdat out=ewretdat2

     (rename = (_1=SELL _2=PORT2 _3=PORT3 _4=PORT4 _5=BUY)

       drop=_NAME_ _LABEL_);

  by date;

  id Forecast_revision_rank;

   var ewret;


/* Compute Long-Short Portfolio Cumulative Returns */

data ewretdat3;

set ewretdat2;

by date;



CUMRET_BUY     = (CUMRET_BUY+1)*(BUY+1)-1;



format BUY SELL LONG_SHORT PORT: CUMRET_: percentn12.1;


proc means data=ewretdat3 n mean t probt;



Below is a screen shot of the table:

Jun-0600036020AAON INC5.0686419455.635555691370.0094413760.004199479412198011201130-Jun-060.334083245May-06Nov-06
Jun-0600036020AAON INC5.0686419455.635555691370.0094413760.00419947941219807978830-Jun-060.4668166485May-06Nov-06
Nov-0600036020AAON INC5.5150617435.730370416110.0340740770.007576944Oct-06Apr-07
Jan-0700036020AAON INC5.4281480585.73037041651-0.0061482850.0024473113Dec-06Jun-07
Feb-0700036020AAON INC5.4854321895.82716049470.0007207370.0006504884Jan-07Jul-07
May-0700036020AAON INC5.8686417945.92987663413-0.0030201390.0057424444Apr-07Oct-07
Jul-0700036020AAON INC5.9081481186.8069133999-0.009602679-0.0027158235Jun-07Dec-07
Aug-0700036020AAON INC6.2044446036.816789792190.0300049490.0026546035Jul-07Jan-08
Oct-0700036020AAON INC5.4103704386.816789792610.033389935-0.0034140253Sep-07Mar-08
Nov-0700036020AAON INC5.6385187226.816789792820.0042216320.0025669413Oct-07Apr-08
Dec-0700036020AAON INC5.8725925026.816789792102-0.0250860910.00248648212198010778031-Dec-07-0.3209169051Nov-07May-08

Please help my guardian angels. Thank You.

Ask a Question
Discussion stats
  • 0 replies
  • 1 in conversation