.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/exotic_options/multi_asset/plot_01_margrabe.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_exotic_options_multi_asset_plot_01_margrabe.py: Margrabe exchange options ========================= William Margrabe (1978) priced the right to exchange one asset for another, :math:`(S_1 - S_2)^+`. Measured in units of the second asset, it is a call on the ratio :math:`S_1/S_2` struck at 1, so the interest rate drops out and only the volatility of the ratio, :math:`\sigma^2 = \sigma_1^2 + \sigma_2^2 - 2\rho\sigma_1\sigma_2`, matters. Change of numeraire, the idea behind this one-line proof, became one of the central tools of derivatives pricing. .. GENERATED FROM PYTHON SOURCE LINES 15-24 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.exotic_options import margrabe_price from financialkit.integrators import correlated_increments S1, S2, T, s1, s2 = 100.0, 100.0, 1.0, 0.25, 0.3 rho = np.linspace(-0.95, 0.95, 50) .. GENERATED FROM PYTHON SOURCE LINES 25-27 Correlation drives the price ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 27-40 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(12, 4)) axes[0].plot(rho, margrabe_price(S1, S2, T, s1, s2, rho), label="closed form") for c in (-0.6, 0.0, 0.6): W = correlated_increments([[1.0, c], [c, 1.0]], T, 1, 20_000, rng=int(10 * c) + 10)[:, 0, :] A = S1 * np.exp(-0.5 * s1**2 * T + s1 * W[:, 0]) B = S2 * np.exp(-0.5 * s2**2 * T + s2 * W[:, 1]) y = np.maximum(A - B, 0.0) # r drops out: simulate with zero rate axes[0].errorbar(c, y.mean(), yerr=2 * y.std() / np.sqrt(y.size), fmt="k.", capsize=3) axes[0].set_xlabel(r"correlation $\rho$") axes[0].set_ylabel("exchange option") axes[0].legend() .. image-sg:: /api/gallery/exotic_options/multi_asset/images/sphx_glr_plot_01_margrabe_001.png :alt: plot 01 margrabe :srcset: /api/gallery/exotic_options/multi_asset/images/sphx_glr_plot_01_margrabe_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 41-44 Only the ratio's volatility matters ----------------------------------- Pairs of volatilities with the same ratio volatility give the same price. .. GENERATED FROM PYTHON SOURCE LINES 44-57 .. code-block:: Python target = 0.3 for s_1 in (0.2, 0.3, 0.4): s_2 = np.linspace(0.05, 0.6, 200) c = (s_1**2 + s_2**2 - target**2) / (2 * s_1 * s_2) ok = np.abs(c) < 1 axes[1].plot(s_2[ok], c[ok], label=rf"$\sigma_1$ = {s_1}") axes[1].set_xlabel(r"$\sigma_2$") axes[1].set_ylabel(r"$\rho$ giving a ratio volatility of 30%") axes[1].set_title(f"all priced at {margrabe_price(100.0, 100.0, 1.0, 0.3, 0.0, 0.0):.4f}") axes[1].legend() fig.tight_layout() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.074 seconds) .. _sphx_glr_download_api_gallery_exotic_options_multi_asset_plot_01_margrabe.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/exotic_options/multi_asset/plot_01_margrabe.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_margrabe.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_margrabe.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_margrabe.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_