Computing returns
For managing financial risk, we need to first measure the risk by analyzing the return series. Here, you are given the S&P 500 price series and you need to plot the daily returns. You will see that large (positive or negative) returns tend to be followed by large returns of either sign, and small returns tend to be followed by small returns. The periods of sustained low volatility and high volatility are called volatility clusters.
At any point in this course:
- feel free to explore the datasets in the Console
- don't hesitate to refer to the slides if you need to check the functions and processes explained in the videos
This course assumes knowledge of xts. To refresh your memory, try the xts in R Cheat Sheet.
This exercise is part of the course
GARCH Models in R
Exercise instructions
- Plot the daily stock prices available in the xts object
sp500prices
. - Use the function
CalculateReturns
from, the packagePerformanceAnalytics
to calculate the corresponding returns and save them in the objectsp500ret
. - Verify that
sp500ret
is of the class xts. - Plot the daily S&P 500 returns and note the changes in return variability over time.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
library(xts)
library(PerformanceAnalytics)
# Plot daily S&P 500 prices
___(___)
# Compute daily returns
sp500ret <- ___(___)
# Check the class of sp500ret
___(___)
# Plot daily returns
___(___)