.. 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_01_cryer_psor.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_01_cryer_psor.py: Cryer's projected SOR ===================== An American option is either held, where it satisfies the Black-Scholes equation, or exercised, where it equals its payoff; each implicit step becomes a linear complementarity problem :math:`Ax \ge b,\ x \ge g,\ (Ax - b)^\top(x - g) = 0`. Colin Cryer (1971) solved it by successive over-relaxation, projecting each update back onto :math:`x \ge g`. :func:`~financialkit.pde_methods.psor` does this inside :class:`~financialkit.pde_methods.CrankNicolson`; the sweep count depends strongly on the relaxation parameter :math:`\omega`. .. GENERATED FROM PYTHON SOURCE LINES 16-30 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.options import CRRTree, black_scholes_price from financialkit.pde_methods import CrankNicolson from financialkit.pde_methods.visualizers import plot_exercise_boundary # Hull, 10th ed., Example 21.1 S, K, T, r, sigma = 50.0, 50.0, 5 / 12, 0.10, 0.40 res = CrankNicolson(200, 100, rannacher_steps=2, american_method="psor").price(S, K, T, r, sigma, option_type="put", american=True) tree = CRRTree(2000).price(S, K, T, r, sigma, option_type="put", american=True).price print(f"PSOR {res.price:.4f}, CRR tree {tree:.4f}, European {black_scholes_price(S, K, T, r, sigma, option_type='put'):.4f}") print(f"{res.lcp_iterations} PSOR sweeps over 100 time steps") .. rst-class:: sphx-glr-script-out .. code-block:: none PSOR 4.2793, CRR tree 4.2839, European 4.0760 1156 PSOR sweeps over 100 time steps .. GENERATED FROM PYTHON SOURCE LINES 31-33 The option and its early-exercise boundary ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(14, 4)) near = res.S < 90 axes[0].plot(res.S[near], res.V[near], label="American put") 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].legend() plot_exercise_boundary(res, ax=axes[1]) .. image-sg:: /api/gallery/pde_methods/american/images/sphx_glr_plot_01_cryer_psor_001.png :alt: plot 01 cryer psor :srcset: /api/gallery/pde_methods/american/images/sphx_glr_plot_01_cryer_psor_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 43-45 Sweeps against the relaxation parameter --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-56 .. code-block:: Python omegas = np.linspace(1.0, 1.8, 9) sweeps = [ CrankNicolson(100, 50, rannacher_steps=2, american_method="psor", omega=w).price(S, K, T, r, sigma, option_type="put", american=True).lcp_iterations for w in omegas ] axes[2].plot(omegas, sweeps, "o-") axes[2].set_xlabel(r"relaxation $\omega$") axes[2].set_ylabel("total sweeps (M = 100, N = 50)") fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.190 seconds) .. _sphx_glr_download_api_gallery_pde_methods_american_plot_01_cryer_psor.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_01_cryer_psor.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_cryer_psor.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_cryer_psor.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_cryer_psor.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_