The problem
Let’s say that we have daily stock returns. We want to convert those returns to cumulative returns for a weekly, monthly or yearly frequency.
Where cumulative returns = (1+Ri1) * (1+Ri2) * (1+R3) * … (1+R4) – 1
Solution
First create the weekly, monthly or year identifier, and then use asrol program.
Let us use this data set [Click here to download], also shown below and find returns for different frequencies.
input id str20 D returns 1 30jun1993 .7437958 1 02jul1993 .0674011 1 06jul1993 .2668857 1 14jul1993 .0454151 1 19jul1993 .1340756 1 29jul1993 .8053644 1 13aug1993 .5861199 1 24sep1993 .3200437 1 19oct1993 .0098762 1 19oct1993 .005197 end g date = date(D, "DMY") drop D
Find weekly cumulative returns
Let us first install asrol from ssc
ssc install asrol
Now create weekly date
gen week = wofd(date)
Now find the returns using asrol
bys id week : asrol returns, stat(product) add(1)
Note : add(1) adds 1 with each returns before multiplication and then subtracts 1 at the end.
Find monthly cumulative returns
gen month = mofd(date) bys id month: asrol returns, stat(product) add(1)
Find yearly cumulative returns
gen year= year(date) bys id year: asrol returns, stat(product) add(1)
Hello,
I am trying to compute several lagged cumulative returns with different rolling windows (1, 3, and 6month; 2 to 12, 2 to 24, 2 to 36months)
However, this function returns an error:
bys id: asrol dailyreturn, stat(product) add(1) window (t 21) gen(mom_1)
Error Message:
PRODUCT(): 3301 subscript invalid
asroldt2(): – function returned error
asrolw(): – function returned error
: – function returned error
I tried different configuration but the same error keeps appearing. Any suggestions why?
statlist thread: https://www.statalist.org/forums/forum/general-stata-discussion/general/1509757-creating-1-3-6-months-cumulative-returns-and-volatility-from-daily-price-data
I have updated asrol. Please type
Let me know if the problem persists.
Hi,
I got a similar error message when using asrol to calculate geometric means.
My code is as follows:
bys id: asrol ret, stat(count gmean) window(time 12) add(1)
The error message is:
GMEAN(): 3301 subscript invalid
asroldt2(): – function returned error
asrolw(): – function returned error
: – function returned error
r(3301);
I tried “ssc install asrol, replace” as you suggested. But it keeps showing the same error. Stat(product) works well.
Can you please give some suggestions for this problem? Thanks.