Aggregating log-return series
In statistics, aggregate data are data combined from several measurements. You just learned that you can compute compute weekly, monthly and quarterly log-returns by summing daily log-returns with the corresponding apply.weekly()
, apply.monthly()
and apply.quarterly()
functions.
For example, you can use the following code to form the quarterly returns for a univariate time series data
and multivariate time series mv_data
:
> # apply.quarterly(x, FUN, ...)
> data_q = apply.quarterly(data, sum)
> mv_data_q = apply.quarterly(mv_data, colSums)
In this exercise, you will practice aggregating time series data using these functions and plotting the results. The data DJ
and DJ_const
are available in your workspace, as are the objects djx
, which contains daily log-returns of the Dow Jones index from 2000-2015, and djreturns
, which contains the daily log-returns for the first four DJ_const
stocks from 2000-2015. Use plot
for univariate time series and plot.zoo
for multivariate time series.
This exercise is part of the course
Quantitative Risk Management in R
Exercise instructions
- Plot the object
djx
. - In one line, plot the weekly log-returns of
djx
with vertical bars. - Plot the monthly log-returns of
djx
with vertical bars. - Plot the object
djreturns
usingplot.zoo
. - Plot the monthly log-returns for
djreturns
with vertical bars usingplot.zoo
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Plot djx
___(___)
# Plot weekly log-returns of djx
___(___, ___)
# Plot monthly log-returns of djx
___(___, ___)
# Plot djreturns
___(___)
# Plot monthly log-returns of djreturns
___(___, ___)