.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/options/closed_form/plot_05_black76.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_closed_form_plot_05_black76.py: Black-76: options on futures ============================ Fischer Black (1976) priced options on commodity futures. A futures contract costs nothing to enter, so its risk-neutral drift is zero and the Black-Scholes argument gives .. math:: c = e^{-rT}[F N(d_1) - K N(d_2)], with the futures price :math:`F` in place of the spot. The same formula prices caps, floors and swaptions in :mod:`financialkit.interest_rate_models`. .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.options import black76_price, black_scholes_price .. GENERATED FROM PYTHON SOURCE LINES 23-25 Hull's futures put (Example 18.7) --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: Python print(f"four-month put on futures at 20, strike 20: {black76_price(20.0, 20.0, 4 / 12, 0.09, 0.25, 'put'):.4f} (Hull: 1.12)") .. rst-class:: sphx-glr-script-out .. code-block:: none four-month put on futures at 20, strike 20: 1.1166 (Hull: 1.12) .. GENERATED FROM PYTHON SOURCE LINES 29-34 Black-76 is Black-Scholes on the forward ---------------------------------------- For a stock with dividend yield :math:`q` the forward is :math:`F = S e^{(r-q)T}`, and both formulas give the same price. .. GENERATED FROM PYTHON SOURCE LINES 34-40 .. code-block:: Python S, T, r, q, sigma = 100.0, 1.0, 0.05, 0.02, 0.25 F = S * np.exp((r - q) * T) K = np.linspace(70, 140, 8) print("max difference:", np.max(np.abs(black76_price(F, K, T, r, sigma) - black_scholes_price(S, K, T, r, sigma, q)))) .. rst-class:: sphx-glr-script-out .. code-block:: none max difference: 0.0 .. GENERATED FROM PYTHON SOURCE LINES 41-43 Calls and puts on futures across maturities ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 43-56 .. code-block:: Python K = np.linspace(60, 140, 161) fig, ax = plt.subplots(figsize=(7, 4)) for T in (0.25, 1.0, 3.0): ax.plot(K, black76_price(100.0, K, T, 0.05, 0.3), label=f"call, T = {T}") ax.plot(K, black76_price(100.0, K, T, 0.05, 0.3, "put"), "--", label=f"put, T = {T}") ax.axvline(100.0, color="k", lw=0.5) ax.set_xlabel("strike K (futures at 100)") ax.set_ylabel("option price") ax.legend(ncol=2) fig.tight_layout() plt.show() .. image-sg:: /api/gallery/options/closed_form/images/sphx_glr_plot_05_black76_001.png :alt: plot 05 black76 :srcset: /api/gallery/options/closed_form/images/sphx_glr_plot_05_black76_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.045 seconds) .. _sphx_glr_download_api_gallery_options_closed_form_plot_05_black76.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/closed_form/plot_05_black76.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_black76.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_black76.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_black76.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_