.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/pde_methods/american/plot_02_brennan_schwartz.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_pde_methods_american_plot_02_brennan_schwartz.py: Brennan-Schwartz American put ============================= Michael Brennan and Eduardo Schwartz (1977) priced the American put with an implicit scheme and a direct solve: eliminate the tridiagonal system starting from the top of the grid, then substitute back upward from :math:`S = 0`, taking the larger of the computed value and the payoff at each node. Because the put is exercised on a single interval at the bottom of the grid, this one pass solves the complementarity problem exactly. :func:`~financialkit.pde_methods.brennan_schwartz` matches PSOR to rounding at a fraction of the cost. .. GENERATED FROM PYTHON SOURCE LINES 16-32 .. code-block:: Python import time import matplotlib.pyplot as plt import numpy as np from financialkit.options import CRRTree from financialkit.pde_methods import CrankNicolson S, K, T, r, sigma = 50.0, 50.0, 5 / 12, 0.10, 0.40 tree = CRRTree(2000).price(S, K, T, r, sigma, option_type="put", american=True).price for method in ("brennan_schwartz", "psor"): t0 = time.perf_counter() res = CrankNicolson(400, 200, rannacher_steps=2, american_method=method).price(S, K, T, r, sigma, option_type="put", american=True) print(f"{method:16s} {res.price:.6f} in {time.perf_counter() - t0:.3f} s, {res.lcp_iterations} iterations") print(f"CRR tree {tree:.6f}") .. rst-class:: sphx-glr-script-out .. code-block:: none brennan_schwartz 4.282866 in 0.128 s, 202 iterations psor 4.282866 in 0.015 s, 3606 iterations CRR tree 4.283922 .. GENERATED FROM PYTHON SOURCE LINES 33-35 The put across spots and maturities ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-52 .. code-block:: Python maturities = [0.1, 0.25, 0.5, 1.0] fig, axes = plt.subplots(1, 2, figsize=(11, 4)) for T_ in maturities: res = CrankNicolson(200, 100, rannacher_steps=2, american_method="brennan_schwartz").price(S, K, T_, r, sigma, option_type="put", american=True) near = res.S < 90 axes[0].plot(res.S[near], res.V[near], label=f"T = {T_}") axes[1].plot(T_ - res.times, res.exercise_boundary, label=f"T = {T_}") axes[0].plot(res.S[near], np.maximum(K - res.S[near], 0.0), "k--", lw=1, label="payoff") axes[0].set_xlabel("spot S") axes[0].set_ylabel("American put") axes[0].legend() axes[1].set_xlabel("time to maturity") axes[1].set_ylabel("critical spot S*") axes[1].legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/pde_methods/american/images/sphx_glr_plot_02_brennan_schwartz_001.png :alt: plot 02 brennan schwartz :srcset: /api/gallery/pde_methods/american/images/sphx_glr_plot_02_brennan_schwartz_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.259 seconds) .. _sphx_glr_download_api_gallery_pde_methods_american_plot_02_brennan_schwartz.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/pde_methods/american/plot_02_brennan_schwartz.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_brennan_schwartz.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_brennan_schwartz.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_brennan_schwartz.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_