.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/exotic_options/binaries/plot_01_digital_options.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_binaries_plot_01_digital_options.py: Reiner-Rubinstein binary options ================================ Mark Rubinstein and Eric Reiner's "Unscrambling the Binary Code" (1991) priced the all-or-nothing payoffs and showed that every vanilla and barrier option is assembled from them. A cash-or-nothing call pays 1 if :math:`S_T > K` and is worth :math:`e^{-rT}N(d_2)`; an asset-or-nothing call pays the share and is worth :math:`Se^{-qT}N(d_1)`. A vanilla call is one asset-or-nothing call minus :math:`K` cash-or-nothing calls. A gap option uses different trigger and payoff strikes and can be worth less than nothing, and a one-touch pays as soon as a barrier is hit. .. GENERATED FROM PYTHON SOURCE LINES 16-25 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.exotic_options import asset_or_nothing_price, cash_or_nothing_price, gap_option_price, one_touch_price from financialkit.options import black_scholes_price K, T, r, sigma = 100.0, 0.5, 0.05, 0.25 S = np.linspace(60.0, 150.0, 300) .. GENERATED FROM PYTHON SOURCE LINES 26-28 A vanilla call from two digitals -------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-39 .. code-block:: Python asset = asset_or_nothing_price(S, K, T, r, sigma) cash = cash_or_nothing_price(S, K, T, r, sigma, cash=K) fig, axes = plt.subplots(1, 3, figsize=(15, 4)) axes[0].plot(S, asset, label="asset-or-nothing call") axes[0].plot(S, cash, label=f"{K:g} cash-or-nothing calls") axes[0].plot(S, asset - cash, lw=3, label="difference") axes[0].plot(S, black_scholes_price(S, K, T, r, sigma), "k--", label="Black-Scholes call") axes[0].set_xlabel("spot S") axes[0].legend() .. image-sg:: /api/gallery/exotic_options/binaries/images/sphx_glr_plot_01_digital_options_001.png :alt: plot 01 digital options :srcset: /api/gallery/exotic_options/binaries/images/sphx_glr_plot_01_digital_options_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-42 The digital's delta spikes at the strike near expiry ---------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python for tau in (0.5, 0.1, 0.02): axes[1].plot(S, cash_or_nothing_price(S, K, tau, r, sigma), label=f"T = {tau:g}") axes[1].set_xlabel("spot S") axes[1].set_ylabel("cash-or-nothing call (pays 1)") axes[1].legend() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 50-56 Gap options and one-touches --------------------------- Haug (2007), Section 4.19.1: a gap call triggered at 50 that pays S_T - 57 is worth a fraction of a cent less than zero. The one-touch pays 1 the first time the price reaches 120 and is worth roughly twice the digital that pays at expiry if S_T > 120 (the reflection principle). .. GENERATED FROM PYTHON SOURCE LINES 56-65 .. code-block:: Python print(f"gap call: {gap_option_price(50.0, 50.0, 57.0, 0.5, 0.09, 0.20):.4f}") axes[2].plot(S[S < 120], one_touch_price(S[S < 120], 120.0, T, r, sigma), label="one-touch at 120") axes[2].plot(S, cash_or_nothing_price(S, 120.0, T, r, sigma), label="digital call, K = 120") axes[2].plot(S[S < 120], 2 * cash_or_nothing_price(S[S < 120], 120.0, T, r, sigma), ":", label="twice the digital") axes[2].set_xlabel("spot S") axes[2].legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none gap call: -0.0053 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.093 seconds) .. _sphx_glr_download_api_gallery_exotic_options_binaries_plot_01_digital_options.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/binaries/plot_01_digital_options.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_digital_options.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_digital_options.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_digital_options.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_