BookmarkSubscribeRSS Feed
Fluorite | Level 6

## Portfolio Formation and Holding Period

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).

Below are my codes:

/* Step 1. Specifying Options */

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

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

%let begdate=01JAN1994;

%let enddate=31DEC2014;

run;

/* 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";

run;

/* 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<=b.date<=a.HDATE2

order by cusip, date;

quit;

/* 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;

run;

/* Portfolio average monthly returns */

proc sort data=umd3; by date Forecast_revision_rank;

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

run;

/* 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;

run;

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;

run;

/* 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;

run;

/* Compute Long-Short Portfolio Cumulative Returns */

data ewretdat3;

set ewretdat2;

by date;

LONG_SHORT=BUY-SELL;

retain CUMRET_BUY CUMRET_SELL CUMRET_LONG_SHORT 0;

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

CUMRET_LOSERS      = (CUMRET_SELL +1)*(SELL +1)-1;

CUMRET_LONG_SHORT  = (CUMRET_LONG_SHORT+1)*(LONG_SHORT+1)-1;

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

run;

proc means data=ewretdat3 n mean t probt;

var BUY SELL LONG_SHORT;

run;

Discussion stats
• 0 replies
• 2235 views
• 1 like
• 1 in conversation