(stochastic_volatility)=

Stochastic Volatility model

:::{post} June 17, 2022 :tags: time series, case study :category: beginner :author: John Salvatier, Colin Carroll, Abhipsha Das :::

Asset prices have time-varying volatility (variance of day over day returns). In some periods, returns are highly variable, while in others very stable. Stochastic volatility models model this with a latent volatility variable, modeled as a stochastic process. The following model is similar to the one described in the No-U-Turn Sampler paper, {cite:p}hoffman2014nuts.

σExponential(50)\sigma \sim Exponential(50)

νExponential(.1)\nu \sim Exponential(.1)

siNormal(si1,σ2)s_i \sim Normal(s_{i-1}, \sigma^{-2})

log(ri)t(ν,0,exp(2si))\log(r_i) \sim t(\nu, 0, \exp(-2 s_i))

Here, $r$ is the daily return series and $s$ is the latent log volatility process.

Build Model

First we load daily returns of the S&P 500, and calculate the daily log returns. This data is from May 2008 to November 2019.

As you can see, the volatility seems to change over time quite a bit but cluster around certain time-periods. For example, the 2008 financial crisis is easy to pick out.

Specifying the model in PyMC mirrors its statistical specification.

Checking the model

Two good things to do to make sure our model is what we expect is to

  1. Take a look at the model structure. This lets us know we specified the priors we wanted and the connections we wanted. It is also handy to remind ourselves of the size of the random variables.
  2. Take a look at the prior predictive samples. This helps us interpret what our priors imply about the data.

We plot and inspect the prior predictive. This is many orders of magnitude larger than the actual returns we observed. In fact, I cherry-picked a few draws to keep the plot from looking silly. This may suggest changing our priors: a return that our model considers plausible would violate all sorts of constraints by a huge margin: the total value of all goods and services the world produces is ~$$10^9$, so we might reasonably not expect any returns above that magnitude.

That said, we get somewhat reasonable results fitting this model anyways, and it is standard, so we leave it as is.

Fit Model

Once we are happy with our model, we can sample from the posterior. This is a somewhat tricky model to fit even with NUTS, so we sample and tune a little longer than default.

Note that the step_size parameter does not look perfect: the different chains look somewhat different. This again indicates some weakness in our model: it may make sense to allow the step_size to change over time, especially over this 11 year time span.

Now we can look at our posterior estimates of the volatility in S&P 500 returns over time.

Finally, we can use the posterior predictive distribution to see the how the learned volatility could have effected returns.

References

:::{bibliography} :filter: docname in docnames :::

Authors

:::{include} ../page_footer.md :::