Skip to content

Commit a9e4656

Browse files
authored
Update stochastic volatility notebook for best practices (#378)
* Bring stochastic volatility notebook in line with style guide Fixing dashes in reference entry Removing extra lines from reference bib file * Adding original author information to stochastic volatility notebook * Adding updated myst file * Fixing misspecified tags and updating author list * Update stochastic_volatility.myst.md
1 parent e3a0e5c commit a9e4656

File tree

3 files changed

+325
-134
lines changed

3 files changed

+325
-134
lines changed

examples/case_studies/stochastic_volatility.ipynb

+276-125
Large diffs are not rendered by default.

examples/references.bib

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ @book{hayes2017introduction
156156
year = {2017},
157157
publisher = {Guilford publications}
158158
}
159+
@article{hoffman2014nuts,
160+
title = {The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo},
161+
author = {Hoffman, Matthew and Gelman, Andrew},
162+
year = {2014},
163+
journal = {Journal of Machine Learning Research},
164+
volume = {15},
165+
issue = {1},
166+
pages = {1593--1623},
167+
url = {https://dl.acm.org/doi/10.5555/2627435.2638586}
168+
}
159169
@misc{hogg2010data,
160170
title = {Data analysis recipes: Fitting a model to data},
161171
author = {David W. Hogg and Jo Bovy and Dustin Lang},

myst_nbs/case_studies/stochastic_volatility.myst.md

+39-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ jupytext:
66
format_version: 0.13
77
jupytext_version: 1.13.7
88
kernelspec:
9-
display_name: Python 3 (ipykernel)
9+
display_name: pymc_env
1010
language: python
11-
name: python3
11+
name: pymc_env
1212
---
1313

14+
(stochastic_volatility)=
1415
# Stochastic Volatility model
1516

17+
:::{post} June 17, 2022
18+
:tags: time series, case study
19+
:category: beginner
20+
:author: John Salvatier
21+
:::
22+
1623
```{code-cell} ipython3
1724
import os
1825
@@ -26,15 +33,15 @@ rng = np.random.RandomState(1234)
2633
az.style.use("arviz-darkgrid")
2734
```
2835

29-
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, Hoffman (2011) p21.
36+
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`.
3037

3138
$$ \sigma \sim Exponential(50) $$
3239

3340
$$ \nu \sim Exponential(.1) $$
3441

3542
$$ s_i \sim Normal(s_{i-1}, \sigma^{-2}) $$
3643

37-
$$ log(r_i) \sim t(\nu, 0, exp(-2 s_i)) $$
44+
$$ \log(r_i) \sim t(\nu, 0, \exp(-2 s_i)) $$
3845

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

@@ -180,11 +187,34 @@ axes[0].set_title("True log returns (black) and posterior predictive log returns
180187
axes[1].set_title("Posterior volatility");
181188
```
182189

183-
## References
184-
185-
1. Hoffman & Gelman. (2011). [The No-U-Turn Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo](http://arxiv.org/abs/1111.4246).
186-
187190
```{code-cell} ipython3
188191
%load_ext watermark
189-
%watermark -n -u -v -iv -w -p aesara,xarray
192+
%watermark -n -u -v -iv -w -p aesara,aeppl,xarray
190193
```
194+
195+
## References
196+
197+
:::{bibliography}
198+
:filter: docname in docnames
199+
:::
200+
201+
+++
202+
203+
## Authors
204+
205+
+++
206+
207+
* Written by John Salvatier
208+
* Updated by Kyle Meyer
209+
* Updated by Thomas Wiecki
210+
* Updated by Chris Fonnesbeck
211+
* Updated by Aaron Maxwell on May 18, 2018 ([pymc#2978](https://github.com/pymc-devs/pymc/pull/2978))
212+
* Updated by Colin Carroll on November 16, 2019 ([pymc#3682](https://github.com/pymc-devs/pymc/pull/3682))
213+
* Updated by Abhipsha Das on July 24, 2021 ([pymc-examples#155](https://github.com/pymc-devs/pymc-examples/pull/155))
214+
* Updated by Michael Osthege on June 1, 2022 ([pymc-examples#343](https://github.com/pymc-devs/pymc-examples/pull/343))
215+
* Updated by Christopher Krapu on June 17, 2022 ([pymc-examples#378](https://github.com/pymc-devs/pymc-examples/pull/378))
216+
217+
+++
218+
219+
:::{include} ../page_footer.md
220+
:::

0 commit comments

Comments
 (0)