09-02-2016 02:48 PM
I would like to compute annual buy and hold return using monthly return like the following.
annual ruturn = (1+January return)(1+February return)(1+March return)-----(1+December return) - 1
The data structure I have is as follows:
gvkey year month monthly return
00001 2000 1 0.002
00001 2000 2 0.001
00001 2000 3 0.003
Do you have a simple SAS code I can refer using retain statement (without using macro)?
Thank you for your help
09-02-2016 03:12 PM - edited 09-02-2016 03:16 PM
This should do what you want but the value is only going to be for the entire year if the last value in each year corresponds to Dec.
I assumed that since you have a key value that you wanted this for each key and that the data is sorted by gvkey year and month.
If you only want the final value add at the end of the datastep: If Last.year then output;
data want; set have; by gvkey year; retain AnReturn; if first.year then AnReturn= (1+ MonthReturn); else AnReturn= AnReturn*(1+MonthReturn); run;
However I suspect you are going to run into precision problems (under flow). you may need to consider an approach with logs or shift ot integer arithmetic and shift back.
09-05-2016 01:08 PM