Hi guys, I have a dataset called crsp3 that contains a time series of stock returns, prices and other variables of interest. I tried to build portfolios based on market equity and B/M by rebalancing every June from 1985 till 2019. I first started by value-weighting all stocks ( check code below) but I am not sure how I can do the same by equally weighting these stocks. Any ideas how I can do this?
data crsp4 (keep=permno date retadj weight_port ME exchcd shrcd cumretx) decme (keep = permno date ME rename=(me=DEC_ME) ) ; set crsp3; by permno date; retain weight_port cumretx me_base; /* portfolio weights and cumulative returns*/ Lpermno=lag(permno); LME=lag(me); if first.permno then do; LME=me/(1+retx); cumretx=sum(1,retx); me_base=LME;weight_port=.;end; else do; if month(date)=7 then do; weight_port= LME; me_base=LME; /* lag ME also at the end of June */ cumretx=sum(1,retx); end; else do; if LME>0 then weight_port=cumretx*me_base; else weight_port=.; cumretx=cumretx*sum(1,retx); end; end; output crsp4; if month(date)=12 and ME>0 then output decme; run;
If you are looking to construct an equal-weight portfolio, read this recent SASGF 2020 paper. It provides an example on page 14: https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2020/4306-2020.pdf
Best of luck,
Shelley
You program doesn't actually calculate weighted returns. It calculates individual returns for each PERMNO. And yes, it also makes a variable ME_BASE, starting each July that you would presumably use to generate portfolio value at the end of each June.
So, for equal-weighted you would have a constant analog to "ME_BASE" to start each July. If that constant analog is 1, this in turn means, all you have to do get the geometric mean of CUMRETX (and finally substract one to get the actual return) over all permno's in each June. That would be the portfolio return for equal-weighted components.
I would first like to thank you for your time. Just to be clear; should I create a new variable in my dataset, for instance, "const" and assigned it constant value x for all permnos across time, then on top of the previous code add an if statement, where I tell sas to find the geometric average and subtract one if const= x in june? I say June because I´m supposed to rebalance every July.
data crsp4b (keep=permno date retadj retx weight_port ME me_base LME exchcd shrcd cumretx) decme (keep = permno date ME rename=(me=DEC_ME) ) ; set crsp3; by permno date; retain weight_port cumretx me_base; /* portfolio weights and cumulative returns*/ Lpermno=lag(permno); LME=lag(me); if first.permno then do; LME=me/(1+retx); cumretx=sum(1,retx); me_base=1;weight_port=.;end; else do; if month(date)=7 then do; weight_port= geomean( cumretx)-1; me_base=1; /* lag ME also at the end of June */ cumretx=sum(1,retx); end; else do; if LME>0 then weight_port=cumretx*me_base; else weight_port=.; cumretx=cumretx*sum(1,retx); end; end; output crsp4b; if month(date)=12 and ME>0 then output decme; run;
Is this what you meant?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.