.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/options/implied_vol/plot_02_breeden_litzenberger.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_options_implied_vol_plot_02_breeden_litzenberger.py: Breeden-Litzenberger risk-neutral density ========================================= Douglas Breeden and Robert Litzenberger (1978) showed that the second strike derivative of the call price is the discounted risk-neutral density of the terminal price, .. math:: f(K) = e^{rT} \frac{\partial^2 c}{\partial K^2}. A butterfly spread around :math:`K` pays off only if :math:`S_T` lands near :math:`K`, so its price is the market's state price for that outcome. Black-Scholes prices give back the lognormal; prices from a two-regime mixture reveal a bimodal market view. .. GENERATED FROM PYTHON SOURCE LINES 18-26 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from scipy.integrate import trapezoid from scipy.stats import lognorm from financialkit.options import black_scholes_price, breeden_litzenberger_density from financialkit.options.visualizers import plot_density .. GENERATED FROM PYTHON SOURCE LINES 27-29 Black-Scholes prices recover the lognormal density -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-41 .. code-block:: Python S, T, r, sigma = 100.0, 0.5, 0.03, 0.25 K = np.linspace(30, 220, 381) res = breeden_litzenberger_density(K, black_scholes_price(S, K, T, r, sigma), T, r) exact = lognorm.pdf(res.strikes, s=sigma * np.sqrt(T), scale=S * np.exp((r - 0.5 * sigma**2) * T)) print(f"max error against the lognormal: {np.max(np.abs(res.density - exact)):.1e}") fig, axes = plt.subplots(1, 2, figsize=(11, 4)) plot_density(res, ax=axes[0]) axes[0].plot(res.strikes, exact, "k:", label="lognormal") axes[0].legend() .. image-sg:: /api/gallery/options/implied_vol/images/sphx_glr_plot_02_breeden_litzenberger_001.png :alt: plot 02 breeden litzenberger :srcset: /api/gallery/options/implied_vol/images/sphx_glr_plot_02_breeden_litzenberger_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none max error against the lognormal: 1.7e-06 .. GENERATED FROM PYTHON SOURCE LINES 42-48 A bimodal market: an event with two outcomes -------------------------------------------- Mix two lognormals with forwards 85 and 115, the same overall forward, as before a binary event. The density from the mixed prices shows both modes, which no single Black-Scholes volatility could produce. .. GENERATED FROM PYTHON SOURCE LINES 48-59 .. code-block:: Python w = 0.5 F = S * np.exp(r * T) mix = w * black_scholes_price(0.85 * S, K, T, r, 0.1) + (1 - w) * black_scholes_price(1.15 * S, K, T, r, 0.1) res_mix = breeden_litzenberger_density(K, mix, T, r) plot_density(res_mix, ax=axes[1], label="two-regime prices") axes[1].axvline(F, color="k", lw=0.5) print(f"total probability: {trapezoid(res_mix.density, res_mix.strikes):.4f}") fig.tight_layout() plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none total probability: 1.0000 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.054 seconds) .. _sphx_glr_download_api_gallery_options_implied_vol_plot_02_breeden_litzenberger.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/options/implied_vol/plot_02_breeden_litzenberger.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_breeden_litzenberger.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_breeden_litzenberger.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_breeden_litzenberger.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_