.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/options/trees/plot_05_barone_adesi_whaley.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_trees_plot_05_barone_adesi_whaley.py: The Barone-Adesi-Whaley approximation ===================================== Giovanni Barone-Adesi and Robert Whaley (1987), building on MacMillan (1986), found an almost closed-form American price. The early-exercise premium solves the Black-Scholes PDE; dropping one small time-derivative term leaves an ordinary differential equation with power-law solutions, and smooth pasting at a critical price :math:`S^*` pins down the coefficient. One scalar root replaces a whole lattice. .. GENERATED FROM PYTHON SOURCE LINES 14-23 .. code-block:: Python import time import matplotlib.pyplot as plt import numpy as np from financialkit.options import CRRTree, barone_adesi_whaley K, T, r, sigma = 100.0, 0.5, 0.08, 0.3 .. GENERATED FROM PYTHON SOURCE LINES 24-26 Accuracy and speed against a 2000-step tree ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 26-46 .. code-block:: Python spots = np.linspace(70, 130, 13) t0 = time.perf_counter() baw = np.array([barone_adesi_whaley(s, K, T, r, sigma, option_type="put").price for s in spots]) t_baw = time.perf_counter() - t0 t0 = time.perf_counter() tree = np.array([CRRTree(2000).price(s, K, T, r, sigma, option_type="put", american=True).price for s in spots]) t_tree = time.perf_counter() - t0 print(f"max |BAW - tree| = {np.max(np.abs(baw - tree)):.4f}; time {t_baw * 1e3:.1f} ms vs {t_tree * 1e3:.0f} ms") res = barone_adesi_whaley(100.0, K, T, r, sigma, option_type="put") print(f"at S = 100: American {res.price:.4f}, European {res.european_price:.4f}, critical price {res.critical_price:.2f}") fig, axes = plt.subplots(1, 2, figsize=(11, 4)) axes[0].plot(spots, baw - tree, "o-") axes[0].axhline(0, color="k", lw=0.5) axes[0].set_xlabel("spot S") axes[0].set_ylabel("BAW - tree") axes[0].set_title("American put, 6 months") .. image-sg:: /api/gallery/options/trees/images/sphx_glr_plot_05_barone_adesi_whaley_001.png :alt: American put, 6 months :srcset: /api/gallery/options/trees/images/sphx_glr_plot_05_barone_adesi_whaley_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none max |BAW - tree| = 0.0863; time 8.3 ms vs 424 ms at S = 100: American 6.8670, European 6.4671, critical price 78.65 Text(0.5, 1.0, 'American put, 6 months') .. GENERATED FROM PYTHON SOURCE LINES 47-49 The critical price across maturities ------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 49-62 .. code-block:: Python maturities = np.linspace(0.02, 3.0, 40) put_crit = [barone_adesi_whaley(100.0, K, t, r, sigma, option_type="put").critical_price for t in maturities] call_crit = [barone_adesi_whaley(100.0, K, t, r, sigma, q=0.10).critical_price for t in maturities] axes[1].plot(maturities, put_crit, label="put: exercise below") axes[1].plot(maturities, call_crit, label="call with q = 10%: exercise above") axes[1].axhline(K, color="k", lw=0.5) axes[1].set_xlabel("time to expiry") axes[1].set_ylabel("critical price") axes[1].legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.539 seconds) .. _sphx_glr_download_api_gallery_options_trees_plot_05_barone_adesi_whaley.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/trees/plot_05_barone_adesi_whaley.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_barone_adesi_whaley.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_barone_adesi_whaley.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_barone_adesi_whaley.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_