Reputation: 141
I am new to R and have a quite basic question I guess. I couldn't find help for my specific issue.
I have a data frame consisting of two columns. The first indicating the year and quarter (e.g. 19901, 19902, 19903 etc.). The second shows the corresponding quarterly return.
Now, I want to annualize the returns. As a result I want to have a data.frame with only a year column and the corresponding annualized return.
I know there is the function Return.annualized from the ‘PerformanceAnalytics’ package. However, this function does not calculate rolling annualized returns.
Is there a nice package or function that could solve my problem?
Any help is really appreciated. Thank you!
Upvotes: 1
Views: 175
Reputation: 225
If you have log returns, they exhibit the nice advantage of being summable over time.
If that's the case you can simply apply a rolling window that sums the four previous quarters.
Let's assume you have a vector or list with quarterly log returns called q_ret
library('zoo')
an_ret <- rollapply(q_ret, 4, sum)
Note, that from a finance perspective, this does not hold with simple returns.
Upvotes: 1