.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/exotic_options/barriers/plot_03_double_barrier.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_exotic_options_barriers_plot_03_double_barrier.py: Ikeda-Kunitomo double barriers ============================== A double knock-out dies if the price leaves a corridor :math:`(L, U)`. Naoto Ikeda and Masaaki Kunitomo (1992) solved it, even for curved (exponential) barriers, with an infinite series of images reflected alternately through both boundaries. The terms decay like :math:`e^{-2n^2\ln^2(U/L)/\sigma^2T}`, so two or three are plenty unless the corridor is very narrow. Unlike a vanilla call, a double knock-out call loses value as volatility rises: more paths hit a barrier. .. GENERATED FROM PYTHON SOURCE LINES 15-27 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.exotic_options import double_barrier_price, plot_barrier_paths from financialkit.integrators import gbm_paths K, L, U, T, r = 100.0, 80.0, 130.0, 0.5, 0.05 fig, axes = plt.subplots(1, 3, figsize=(15, 4)) t, paths = gbm_paths(100.0, r, 0.25, T, 100, 40, rng=0) plot_barrier_paths(t, paths, [L, U], ax=axes[0]) .. image-sg:: /api/gallery/exotic_options/barriers/images/sphx_glr_plot_03_double_barrier_001.png :alt: 12 of 40 paths knocked out :srcset: /api/gallery/exotic_options/barriers/images/sphx_glr_plot_03_double_barrier_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 28-30 The corridor value and its volatility ------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 30-38 .. code-block:: Python S = np.linspace(L, U, 300) for sigma in (0.1, 0.2, 0.3, 0.4): axes[1].plot(S, double_barrier_price(S, K, L, U, T, r, sigma), label=rf"$\sigma$ = {sigma:.0%}") axes[1].set_xlabel("spot S") axes[1].set_ylabel("double knock-out call") axes[1].legend() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 39-42 How many images? ---------------- The error of the series truncated at :math:`|n| \le N`, against :math:`N = 20`. .. GENERATED FROM PYTHON SOURCE LINES 42-52 .. code-block:: Python for width, (lo, hi) in (("wide", (60.0, 160.0)), ("medium", (80.0, 130.0)), ("narrow", (95.0, 110.0))): ref = double_barrier_price(100.0, 100.0, lo, hi, T, r, 0.3, n_terms=20) err = [abs(double_barrier_price(100.0, 100.0, lo, hi, T, r, 0.3, n_terms=n) - ref) + 1e-17 for n in range(0, 6)] axes[2].semilogy(range(0, 6), err, "o-", label=f"{width}: ({lo:g}, {hi:g})") axes[2].set_xlabel("terms N") axes[2].set_ylabel("truncation error") axes[2].legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.730 seconds) .. _sphx_glr_download_api_gallery_exotic_options_barriers_plot_03_double_barrier.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/exotic_options/barriers/plot_03_double_barrier.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_double_barrier.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_double_barrier.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_double_barrier.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_