.. 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_01_merton_jump_diffusion.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_01_merton_jump_diffusion.py: Merton's jump diffusion ======================= Robert Merton (1976) added Poisson jumps with lognormal sizes to geometric Brownian motion. If the jump risk is diversifiable it is not priced, and conditioning on the number of jumps turns the option into a Poisson mixture of Black-Scholes prices with adjusted rates and volatilities. Jumps fatten the tails of the return distribution, and because a few jumps matter far more over a week than over five years, they make short-dated smiles much steeper than long-dated ones. .. GENERATED FROM PYTHON SOURCE LINES 15-25 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from scipy.stats import norm from financialkit.stochastic_volatility import MertonJumpModel, cos_density, merton_jump_price from financialkit.stochastic_volatility.visualizers import plot_density, plot_smile S, r = 100.0, 0.03 m = MertonJumpModel(sigma=0.15, lam=0.5, mu_j=-0.15, delta=0.1) .. GENERATED FROM PYTHON SOURCE LINES 26-28 The series against simulation ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 28-33 .. code-block:: Python x = m.sample_terminal(1.0, 200_000, rng=0) pay = np.exp(-r) * np.maximum(S * np.exp(r) * np.exp(x) - 100.0, 0.0) print(f"Merton series {merton_jump_price(S, 100.0, 1.0, r, m):.4f}, Monte Carlo {pay.mean():.4f} +/- {2 * pay.std() / np.sqrt(pay.size):.4f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Merton series 9.0558, Monte Carlo 9.0985 +/- 0.0555 .. GENERATED FROM PYTHON SOURCE LINES 34-36 Fat tails --------- .. GENERATED FROM PYTHON SOURCE LINES 36-46 .. code-block:: Python grid = np.linspace(-1.0, 0.6, 400) dens = cos_density(m, grid, 1.0) c1, c2, _ = m.cumulants(1.0) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) plot_density(grid, dens, ax=ax1, label="Merton", log=True) ax1.plot(grid, norm.pdf(grid, c1, np.sqrt(c2)), "k--", lw=1, label="normal, same mean and variance") ax1.set_ylim(1e-4, 5) ax1.legend() .. image-sg:: /api/gallery/stochastic_volatility/jumps/images/sphx_glr_plot_01_merton_jump_diffusion_001.png :alt: plot 01 merton jump diffusion :srcset: /api/gallery/stochastic_volatility/jumps/images/sphx_glr_plot_01_merton_jump_diffusion_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 47-49 Smiles flatten with maturity ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-57 .. code-block:: Python for T in (0.1, 0.5, 2.0): F = S * np.exp(r * T) K = F * np.exp(np.linspace(-0.35, 0.25, 25) * np.sqrt(T)) plot_smile(K, m.implied_vol(S, K, T, r), forward=F, ax=ax2, label=f"T = {T}") fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.124 seconds) .. _sphx_glr_download_api_gallery_stochastic_volatility_jumps_plot_01_merton_jump_diffusion.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_01_merton_jump_diffusion.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_merton_jump_diffusion.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_merton_jump_diffusion.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_merton_jump_diffusion.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_