Roll, roll, roll
You can visualize the time-variation in volatility by using the function chart.RollingPerformance() in the package PerformanceAnalytics
. An important tuning parameter is the choice of the window length. The shorter the window, the more responsive the rolling volatility estimate is to recent returns. The longer the window, the smoother it will be. The function sd.annualized
lets you compute annualized volatility under the assumption that the number of trading days in a year equals the number specified in the scale
argument.
In this exercise you need to complete the code to compute the rolling estimate of annualized volatility for the daily S&P 500 returns in sp500ret
for the period 2005 until 2017.
This exercise is part of the course
GARCH Models in R
Exercise instructions
- Load the package
PerformanceAnalytics
. - Compute the one month estimate, setting the scale argument to the number of trading days in a year.
- Compute the three months estimate, setting the scale argument to the number of trading days in a year.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load the package PerformanceAnalytics
___
# Showing two plots on the same figure
par(mfrow=c(2,1))
# Compute the rolling 1 month estimate of annualized volatility
chart.RollingPerformance(R = sp500ret["2000::2017"], width = ___,
FUN = "sd.annualized", scale = ___, main = "One month rolling volatility")
# Compute the rolling 3 months estimate of annualized volatility
chart.RollingPerformance(R = ___, width = ___,
FUN = ___, scale = ___, main = "Three months rolling volatility")