.. 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_03_volatility_smile.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_03_volatility_smile.py: The volatility smile ==================== Under Black-Scholes every strike has the same implied volatility. Before October 1987 index options roughly agreed; after the crash, low-strike puts became permanently more expensive, and implied volatility fell steeply with the strike (Rubinstein 1994). Inverting a strip of option prices strike by strike shows the market's departure from the lognormal. Here the prices come from two simple arbitrage-free models: a mixture of volatilities (a symmetric smile) and a mixture of a normal regime with a crash regime (a skew). .. GENERATED FROM PYTHON SOURCE LINES 16-25 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.options import black_scholes_price, implied_vol_smile from financialkit.options.visualizers import plot_smile S, T, r = 100.0, 0.5, 0.02 K = np.linspace(65, 135, 29) .. GENERATED FROM PYTHON SOURCE LINES 26-28 Flat: Black-Scholes prices -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-32 .. code-block:: Python flat = implied_vol_smile(black_scholes_price(S, K, T, r, 0.2), K, S, T, r) print("Black-Scholes prices, implied vol range:", np.round([flat.vols.min(), flat.vols.max()], 6)) .. rst-class:: sphx-glr-script-out .. code-block:: none Black-Scholes prices, implied vol range: [0.2 0.2] .. GENERATED FROM PYTHON SOURCE LINES 33-35 Smile: uncertain volatility --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python smile_prices = 0.5 * black_scholes_price(S, K, T, r, 0.12) + 0.5 * black_scholes_price(S, K, T, r, 0.32) smile = implied_vol_smile(smile_prices, K, S, T, r) .. GENERATED FROM PYTHON SOURCE LINES 40-45 Skew: a small chance of a crash ------------------------------- With probability 10% the forward is 25% lower; the other regime's forward is raised so the overall forward is unchanged. .. GENERATED FROM PYTHON SOURCE LINES 45-58 .. code-block:: Python p_crash, drop = 0.10, 0.25 up = (1 - p_crash * (1 - drop)) / (1 - p_crash) skew_prices = p_crash * black_scholes_price(S * (1 - drop), K, T, r, 0.3) + (1 - p_crash) * black_scholes_price(S * up, K, T, r, 0.15) skew = implied_vol_smile(skew_prices, K, S, T, r) fig, ax = plt.subplots(figsize=(7, 4)) plot_smile(flat, ax=ax, label="Black-Scholes: flat", moneyness=True) plot_smile(smile, ax=ax, label="vol mixture: smile", moneyness=True) plot_smile(skew, ax=ax, label="crash mixture: skew", moneyness=True) fig.tight_layout() plt.show() .. image-sg:: /api/gallery/options/implied_vol/images/sphx_glr_plot_03_volatility_smile_001.png :alt: plot 03 volatility smile :srcset: /api/gallery/options/implied_vol/images/sphx_glr_plot_03_volatility_smile_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.089 seconds) .. _sphx_glr_download_api_gallery_options_implied_vol_plot_03_volatility_smile.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_03_volatility_smile.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_volatility_smile.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_volatility_smile.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_volatility_smile.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_