Get startedGet started for free

Spotting a volatile time series

In this exercise you will plot the Dow Jones log-returns for 2008-2011 alongside independent and identically distributed (iid) normal data and iid Student t data.

The xts object djx contains the Dow Jones index and the objects npars and tpars contain the parameter estimates that are obtained when a normal distribution and a t distribution are fitted to djx. All three objects are loaded in your workspace.

In this exercise, you will generate a normal sample from the fitted model by generating standard normal data, scaling them with the second component npars[2] and shifting them with the first component npars[1]. For the Student t sample you will do something similar but note that this time the first component tpars[1] contains the degree of freedom parameter and tpars[2] and tpars[3] contain the location and scale parameters.

After making the plots, you should compare the behavior of the real returns with that of the iid returns, particularly around the 2008 financial crisis.

This exercise is part of the course

Quantitative Risk Management in R

View Course

Exercise instructions

  • Compute the length n of djx.
  • Generate a normal sample of size n with parameters given by npars and assign the data to ndata.
  • Generate a t sample of size n with parameters given by tpars and assign the data to tdata.
  • Convert ndata and tdata into xts objects named ndatax and tdatax with the same dates as djx.
  • Merge the time series djx, ndatax and tdatax into a single object called alldata and plot with plot.zoo() using type = "h".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Compute the length n of djx 
n <- ___

#  Generate a normal sample of size n with parameters given by npars
ndata <- rnorm(___)*npars[2] + npars[1]

# Generate a t-distributed sample of size n with paramaters given by tpars
___ <- rt(___, df = ___)*tpars[3] + tpars[2]

# Make ndata and tdata into xts objects
ndatax <- xts(___, time(djx))
tdatax <- xts(___, time(djx))

# Merge djx, ndatax, and tdatax and plot
alldata <- ___
plot.zoo(___, ___, ylim = range(alldata))
Edit and Run Code