.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/stochastic_volatility/jumps/plot_02_madan_seneta_variance_gamma.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_stochastic_volatility_jumps_plot_02_madan_seneta_variance_gamma.py: Madan and Seneta's variance gamma ================================= Madan and Seneta (1990) ran a Brownian motion on a random business clock: gamma-distributed time :math:`G_t`, with variance rate :math:`\nu`. The result, :math:`\sigma W_{G_t}`, is a pure-jump Lévy process with infinitely many small jumps, symmetric, and with tails heavier than the normal's but lighter than a power law. The density is closed form in terms of a modified Bessel function. The clock's variance :math:`\nu` sets the excess kurtosis (:math:`3\nu/T`). .. GENERATED FROM PYTHON SOURCE LINES 15-33 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from scipy.stats import norm from financialkit.stochastic_volatility import VarianceGammaModel from financialkit.stochastic_volatility.visualizers import plot_density, plot_smile T, sigma = 0.5, 0.2 x = np.linspace(-0.8, 0.8, 401) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) for nu in (0.05, 0.2, 0.5): m = VarianceGammaModel(sigma=sigma, nu=nu, theta=0.0) plot_density(x, m.pdf(x, T), ax=ax1, label=f"nu = {nu}", log=True) ax1.plot(x, norm.pdf(x, -0.5 * sigma**2 * T, sigma * np.sqrt(T)), "k--", lw=1, label="normal") ax1.set_ylim(1e-4, 20) ax1.legend() .. image-sg:: /api/gallery/stochastic_volatility/jumps/images/sphx_glr_plot_02_madan_seneta_variance_gamma_001.png :alt: plot 02 madan seneta variance gamma :srcset: /api/gallery/stochastic_volatility/jumps/images/sphx_glr_plot_02_madan_seneta_variance_gamma_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 34-36 Subordination: sampling and the density agree --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 36-41 .. code-block:: Python m = VarianceGammaModel(sigma=sigma, nu=0.2, theta=0.0) draws = m.sample_terminal(T, 100_000, rng=0) print(f"sample excess kurtosis {np.mean((draws - draws.mean()) ** 4) / draws.var() ** 2 - 3:.2f}, theory 3 nu / T = {3 * 0.2 / T:.2f}") .. rst-class:: sphx-glr-script-out .. code-block:: none sample excess kurtosis 1.19, theory 3 nu / T = 1.20 .. GENERATED FROM PYTHON SOURCE LINES 42-44 A symmetric smile ----------------- .. GENERATED FROM PYTHON SOURCE LINES 44-52 .. code-block:: Python S, r = 100.0, 0.0 K = S * np.exp(np.linspace(-0.4, 0.4, 21)) for nu in (0.05, 0.2, 0.5): plot_smile(K, VarianceGammaModel(sigma, nu).implied_vol(S, K, T, r), forward=S, ax=ax2, label=f"nu = {nu}") fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.132 seconds) .. _sphx_glr_download_api_gallery_stochastic_volatility_jumps_plot_02_madan_seneta_variance_gamma.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/stochastic_volatility/jumps/plot_02_madan_seneta_variance_gamma.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_madan_seneta_variance_gamma.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_madan_seneta_variance_gamma.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_madan_seneta_variance_gamma.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_