.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/options/trees/plot_06_leisen_reimer.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_06_leisen_reimer.py: The Leisen-Reimer tree ====================== Dietmar Leisen and Matthias Reimer (1996) removed the binomial tree's oscillation. Instead of fixing :math:`u` and :math:`d` from the volatility, they choose the probabilities so that the tree's cumulative binomial distribution reproduces Black-Scholes's :math:`N(d_2)` and :math:`N(d_1)`, using the Peizer-Pratt inversion of the normal onto the binomial. The tree is centred on the strike, and European prices converge smoothly at order :math:`1/n^2`. .. GENERATED FROM PYTHON SOURCE LINES 15-24 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.options import CRRTree, LeisenReimerTree, black_scholes_price from financialkit.options.visualizers import plot_tree_convergence S, K, T, r, sigma = 100.0, 110.0, 1.0, 0.05, 0.25 exact = black_scholes_price(S, K, T, r, sigma) .. GENERATED FROM PYTHON SOURCE LINES 25-27 Second-order convergence ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 27-43 .. code-block:: Python steps = np.arange(11, 402, 10) crr = [CRRTree(n).price(S, K, T, r, sigma).price for n in steps] lr = [LeisenReimerTree(n).price(S, K, T, r, sigma).price for n in steps] order = np.polyfit(np.log(steps), np.log(np.abs(np.array(lr) - exact)), 1)[0] print(f"Leisen-Reimer empirical order: {-order:.2f}") err_crr = abs(CRRTree(51).price(S, K, T, r, sigma).price - exact) err_lr = abs(LeisenReimerTree(51).price(S, K, T, r, sigma).price - exact) print(f"error with 51 steps: CRR {err_crr:.1e}, Leisen-Reimer {err_lr:.1e}") fig, axes = plt.subplots(1, 2, figsize=(11, 4)) plot_tree_convergence(steps, crr, exact, ax=axes[0], label="CRR") plot_tree_convergence(steps, lr, exact, ax=axes[0], label="Leisen-Reimer") axes[0].loglog(steps, 1.0 / steps**2, "k:", label="1/n^2") axes[0].legend() .. image-sg:: /api/gallery/options/trees/images/sphx_glr_plot_06_leisen_reimer_001.png :alt: plot 06 leisen reimer :srcset: /api/gallery/options/trees/images/sphx_glr_plot_06_leisen_reimer_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Leisen-Reimer empirical order: 1.98 error with 51 steps: CRR 8.7e-03, Leisen-Reimer 1.8e-04 .. GENERATED FROM PYTHON SOURCE LINES 44-46 American puts converge smoothly too ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-58 .. code-block:: Python reference = LeisenReimerTree(2001).price(S, K, T, r, sigma, option_type="put", american=True).price steps = np.arange(11, 302, 10) axes[1].plot(steps, [CRRTree(n).price(S, K, T, r, sigma, option_type="put", american=True).price for n in steps], label="CRR") axes[1].plot(steps, [LeisenReimerTree(n).price(S, K, T, r, sigma, option_type="put", american=True).price for n in steps], label="Leisen-Reimer") axes[1].axhline(reference, color="k", ls=":", label="LR, 2001 steps") axes[1].set_xlabel("time steps n") axes[1].set_ylabel("American put") axes[1].legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.264 seconds) .. _sphx_glr_download_api_gallery_options_trees_plot_06_leisen_reimer.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_06_leisen_reimer.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_06_leisen_reimer.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_06_leisen_reimer.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_06_leisen_reimer.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_