Realized monthly returns
Realized monthly returns
hi there,
I am trying to compute the realized monthly returns where months have irregular number of days (between 20 and 22 days).
I have tried several alternatives of looping over dates such as the test code below but nothing seems to work as the date index once it reaches the last day of the month then it acts on the month (so instead of stopping on 31 December it carries onto February) even though the month index is fixed.
Could you please help with this?
Many thanks.
comp k = 1975, j = 01, l = 01
do i = 0, 22
disp %DATELABEL((k):(j):(l+i)) ruk((k):(j):(l+i))
end do i
I am trying to compute the realized monthly returns where months have irregular number of days (between 20 and 22 days).
I have tried several alternatives of looping over dates such as the test code below but nothing seems to work as the date index once it reaches the last day of the month then it acts on the month (so instead of stopping on 31 December it carries onto February) even though the month index is fixed.
Could you please help with this?
Many thanks.
comp k = 1975, j = 01, l = 01
do i = 0, 22
disp %DATELABEL((k):(j):(l+i)) ruk((k):(j):(l+i))
end do i
Re: Realized monthly returns
Are you using CALENDAR daily data? Or do you have the date information coded into the data set (either year-month-day as separate series or something like yyyymmdd). If the former, the RATS calendar functions all wrap automatically, so
cal(daily) 2000:1:1
disp %datelabel(2000:13:1)
will show
2001:01:01
So something like
set monthreturns 1 120 = p((2000:(t+1):1)-1)-p((2000:t:1)-1)
will compute the monthly changes in p (defined as the difference from the last period of the previous month to the last period of the current month) for the 10 year period starting January 2000.
cal(daily) 2000:1:1
disp %datelabel(2000:13:1)
will show
2001:01:01
So something like
set monthreturns 1 120 = p((2000:(t+1):1)-1)-p((2000:t:1)-1)
will compute the monthly changes in p (defined as the difference from the last period of the previous month to the last period of the current month) for the 10 year period starting January 2000.
Re: Realized monthly returns
Hi Tom,
thanks for the suggestion. Unfortunately, it won't work as I have to sum over days to compute realized monthly returns.
My code below perhaps makes it a bit clearer. The %IF instruction works fine but it is not clear to me how to start from September run to December and set the month index back to 1 (January). Can you suggest a solution?
Thank you.
OPEN DATA "C:\G71.xls"
CALENDAR(D) 1970:10:09
DATA(FORMAT=xls,ORG=columns) 1970:10:09 2014:10:11 UK US
set RUK = log(uk/uk{1})
comp X = 0 , k = 1970, j = 10, l = 09
SET X = 0
comp k = 1971
do j = 1, 12
do i = 1, 22
set x i i = %if(k:j:I.GE.(k:(j+1):01),0,UK(k:j:I))
END DO I
comp rmuk = %sum(x)
disp rmuk
clear x
end do j
thanks for the suggestion. Unfortunately, it won't work as I have to sum over days to compute realized monthly returns.
My code below perhaps makes it a bit clearer. The %IF instruction works fine but it is not clear to me how to start from September run to December and set the month index back to 1 (January). Can you suggest a solution?
Thank you.
OPEN DATA "C:\G71.xls"
CALENDAR(D) 1970:10:09
DATA(FORMAT=xls,ORG=columns) 1970:10:09 2014:10:11 UK US
set RUK = log(uk/uk{1})
comp X = 0 , k = 1970, j = 10, l = 09
SET X = 0
comp k = 1971
do j = 1, 12
do i = 1, 22
set x i i = %if(k:j:I.GE.(k:(j+1):01),0,UK(k:j:I))
END DO I
comp rmuk = %sum(x)
disp rmuk
clear x
end do j
Re: Realized monthly returns
Do an ACCUM on the series and then take the differences on that as I showed.