Programming the statistical procedures from SAS

Proc rank to form portfolios

Reply
Occasional Contributor
Posts: 5

Proc rank to form portfolios

[ Edited ]

hello everyone, I need your help with my sas code.

 

I need to sort the funds based on their concentration measure into quintile portfolios at the end of each quarter.  Then, I need to measure the equally weighted return for each  quintiles portfolio for the following quarter and rebalance the portfolio each quarter.  The goal is to see wether the difference between  quintile 5 and quintile 1 is positive and significant i.e to test wether higher concentration generate higher alpha.

                 

 

I have tried the following sas code but I am not sure about the J and k and if what I am doing is correct , any comments would be much appreciated. I have also posted a part of my dataset,  for each quarter I have for different id funds  their respective alphas and concentration measures.

%let J=3;  /*NUMBER OF PRIOR MONTHS USED TO CREATE MOMENTUM PORTFOLIOS */
*** 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 difference between quintiles ******************************************************************************** *****; 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; 5_1=quintile5-quintile1; run; proc means data=ewretdat3 n mean std t probt; var 5_1 quintile5 quintile1; run;

 

Ask a Question
Discussion stats
  • 0 replies
  • 112 views
  • 0 likes
  • 1 in conversation