Hello everyone. I need your help with my sas code. At each quarter, I need to sort the funds into quintiles based on the concentration measure . Then, I need to calculate the equally weighted returns of each quintile portfolio for the following quarter and rebalance the portfolio at each quarter. I am not sure about about the J and K and about the formation of portfolios. I have posted some observation of my dataset.. At each quarter , I have multiple funds id for which I have their alpha and concentration measures. Thank you in advance for your help and your comments *** NUMBER OF PRIOR MONTHS USED TO CREATE PORTFOLIOS;
%let J=3;
*** HOLDING PERIOD IN MONTHS AFTER PORTFOLIO CREATION;
%let K=3;
*** BEGINING SAMPLE PERIOD;
%let begyear=2005;
*** ENDING SAMPLE PERIOD;
%let endyear=2016;
*****************************************************************************;
proc sql;
create table getr_3
as select distinct a.id, a.report_date,alpha,concentration
from getr_2 (keep= id report_Date) as a, getr_2 as b
where a.id=b.id
and 0<=intck('month', b.report_date, a.report_date)<&J
order by id, report_Date;
quit;
proc sort data=getr_3; by report_date; run;
proc rank data=getr_3 out=vol1 group=5;
by report_date;
var concentration;
ranks volr;
run;
data vol2;
set vol1;
volr=volr+1;
run;
4. Assign Ranks to the Next 1 (K) Month After Portfolio Formation
********************************************************************************;
* Portfolio return are average monthly returns rebalanced monthly;
proc sql;
create table msfx2
as select distinct a.volr, a.report_date as form_date, a.id, b.report_date, b.alpha,b.concentration
from vol2 as a, getr_2 as b
where a.id=b.id
and 0<intck('month',a.report_date,b.report_date)<=&K;
quit;
**5. Calculate Equally-Weighted Average Monthly Returns
********************************************************************************;
proc sort data=msfx2; by report_date volr form_date ; run;
* Portfolio monthly return series;
proc means data = msfx2 noprint;
by report_date volr form_date;
var alpha;
output out = msfx3 mean=ret;
run;
* Portfolio average monthly return;
proc sort data=msfx3; by report_date volr;
where year(report_date) between &begyear and &endyear;
run;
proc means data = msfx3 noprint;
by report_date volr;
var ret;
output out = ewretdat mean= ewret;
run;
proc sort data=ewretdat; by volr ; run;
Title "Table 1: Returns of Portfolios";
Title2 "Portfolios based on &J month lagged return and held for &K months";
proc means data=ewretdat mean std t probt;
class volr;
var ewret;
run;
**6. Calculate Buy-Sell Portfolio Returns
********************************************************************************
*****;
proc sort data=ewretdat; by report_date volr; run;
proc transpose data=ewretdat out=ewretdat2
(rename = (_1=quintile1 _2=PORT2 _3=PORT3 _4=PORT4 _5=quintile5
));
by report_date;
id volr;
var ewret;
run;
data ewretdat3;
set ewretdat2;
quintile5_quintile1=quintile5-quintile1;
run;
proc means data=ewretdat3 n mean std t probt;
var quintile5 quintile1 quintile5_quintile1;
run;
... View more