.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/stochastic_volatility/smile/plot_02_svi.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_smile_plot_02_svi.py: Gatheral's SVI ============== Jim Gatheral presented the stochastic volatility inspired (SVI) parametrisation at Global Derivatives in 2004: the total implied variance :math:`w(k) = \sigma_{BS}^2 T` in log-moneyness :math:`k`, .. math:: w(k) = a + b\left[\rho(k - m) + \sqrt{(k - m)^2 + \sigma^2}\right], a hyperbola whose asymptotes are the linear wings Lee's theorem requires. It is the large-maturity limit of Heston's smile, and five parameters fit equity smiles remarkably well. Durrleman's function :math:`g(k)` must stay non-negative for the implied density to be a density; here SVI is fitted to a Heston smile and checked. .. GENERATED FROM PYTHON SOURCE LINES 19-46 .. image-sg:: /api/gallery/stochastic_volatility/smile/images/sphx_glr_plot_02_svi_001.png :alt: plot 02 svi :srcset: /api/gallery/stochastic_volatility/smile/images/sphx_glr_plot_02_svi_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none T = 0.5: a = 0.0078, b = 0.0468, rho = -0.656, m = 0.096, sigma = 0.045; rms vol error 10.6 bp T = 1.0: a = 0.0106, b = 0.0779, rho = -0.613, m = 0.115, sigma = 0.115; rms vol error 1.8 bp T = 2.0: a = 0.0099, b = 0.1167, rho = -0.508, m = 0.192, sigma = 0.240; rms vol error 0.8 bp | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.stochastic_volatility import HestonModel, durrleman_g, svi_fit from financialkit.stochastic_volatility.visualizers import plot_smile S, r = 100.0, 0.0 m = HestonModel(0.04, 1.5, 0.04, 0.6, -0.7) k = np.linspace(-0.6, 0.4, 21) fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4)) for T in (0.5, 1.0, 2.0): iv = m.implied_vol(S, S * np.exp(k), T, r) fit = svi_fit(k, iv**2 * T, T) rms = np.sqrt(np.mean((fit.implied_vol(k) - iv) ** 2)) print(f"T = {T}: a = {fit.a:.4f}, b = {fit.b:.4f}, rho = {fit.rho:.3f}, m = {fit.m:.3f}, sigma = {fit.sigma:.3f}; rms vol error {rms * 1e4:.1f} bp") line = ax1.plot(k, iv, "o", ms=3)[0] kk = np.linspace(-1.0, 0.8, 200) plot_smile(S * np.exp(kk), fit.implied_vol(kk), forward=S, ax=ax1, label=f"SVI, T = {T}", color=line.get_color()) ax2.plot(kk, durrleman_g(kk, fit.a, fit.b, fit.rho, fit.m, fit.sigma), label=f"T = {T}") ax2.axhline(0.0, color="k", lw=0.8) ax2.set_xlabel("log-moneyness k") ax2.set_ylabel("Durrleman g(k)") ax2.legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.178 seconds) .. _sphx_glr_download_api_gallery_stochastic_volatility_smile_plot_02_svi.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/smile/plot_02_svi.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_svi.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_svi.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_svi.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_