Learn how to combine daily log returns into weekly or monthly series in R using the XTS package. Log returns over multiple days equal the sum of daily returns, so you use apply.weekly or apply.monthly with sum for single assets, or colSums for multiple assets. The resulting dates are seven days apart for weekly data and end-of-month for monthly.
Chapters
I remarked before that it is easy to aggregate shorter interval log returns like daily returns. To obtain longer interval returns like weekly or monthly returns, effectively you just add them up. Why would you want to do this? Well, by aggregating returns you can study the risks over longer time horizons such as a month, a quarter, or a year. There is some simple mathematics behind the aggregation of log returns. Let's assume that the series XT are daily log returns calculated from daily risk factor values zt. Let's assume further that ZT is a price series for some asset that is traded on weekdays. To get the log return for a whole trading week starting on day T, effectively the previous Friday evening before markets open on the Monday morning, and ending on day T5 Friday evening again, you would calculate the difference log of ZT5 minus log of ZT. It can be shown that this is just the sum of the log returns for each of the trading days, and a similar calculation works for any aggregation period. To do this in R, you can use a set of functions in the XTS package with names like Apply Weekly and Apply Monthly. If the object SP500X is an XTS object containing daily log returns, you obtain weekly returns by applying the sum function within the Apply Weekly function. Note how the returns now have date stamps that are seven days apart. Similarly, to get monthly returns, you apply the sum function within the Apply Monthly function. Now the date stamps are the last days of each calendar month. Note that if you have a multivariate time series containing, for example, multiple stock prices, you have to apply the function callsums instead of sum. Look out for an example of that at the end of the next exercise. So now it's time to practice aggregating log return series.