.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fixed_income/swaps/plot_02_interest_rate_swap.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_fixed_income_swaps_plot_02_interest_rate_swap.py: The plain-vanilla interest-rate swap ==================================== The single-currency swap followed within a year of the IBM-World Bank deal. One side pays a fixed rate and the other pays a floating rate on the same notional. The floating leg is worth par on every reset date, so the swap is worth a floating-rate note minus a fixed-coupon bond. The par swap rate is the coupon that makes the two equal. .. GENERATED FROM PYTHON SOURCE LINES 13-18 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.fixed_income import NelsonSiegelCurve, ZeroCurve, interest_rate_swap_value, swap_rate .. GENERATED FROM PYTHON SOURCE LINES 19-21 Hull's Example 7.1 ------------------ .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python curve = ZeroCurve([0.25, 0.75, 1.25], [0.10, 0.105, 0.11]) v = interest_rate_swap_value(curve, 100.0, 0.08, 1.25, pay_fixed=False, floating_rate=0.102) print(f"fixed bond {v.receive_leg:.3f}, floating note {v.pay_leg:.3f}, swap to fixed receiver {v.value:.3f} ($m)") .. rst-class:: sphx-glr-script-out .. code-block:: none fixed bond 98.238, floating note 102.505, swap to fixed receiver -4.267 ($m) .. GENERATED FROM PYTHON SOURCE LINES 27-29 The par swap curve ------------------ .. GENERATED FROM PYTHON SOURCE LINES 29-39 .. code-block:: Python ns = NelsonSiegelCurve(0.045, -0.025, 0.01, 2.0) T = np.arange(1, 31, dtype=float) fig, axes = plt.subplots(1, 2, figsize=(10, 4)) axes[0].plot(T, 100 * swap_rate(ns, T), "o-", ms=3, label="par swap rate") axes[0].plot(T, 100 * ns.zero_rate(T), label="zero rate") axes[0].set_xlabel("swap maturity (years)") axes[0].set_ylabel("rate (%)") axes[0].legend() .. image-sg:: /api/gallery/fixed_income/swaps/images/sphx_glr_plot_02_interest_rate_swap_001.png :alt: plot 02 interest rate swap :srcset: /api/gallery/fixed_income/swaps/images/sphx_glr_plot_02_interest_rate_swap_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 40-42 A 10-year payer swap after parallel moves ----------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 42-50 .. code-block:: Python K = swap_rate(ns, 10.0) shifts = np.linspace(-0.02, 0.02, 41) axes[1].plot(1e4 * shifts, [interest_rate_swap_value(ns.shifted(s), 100.0, K, 10.0).value for s in shifts]) axes[1].axhline(0.0, color="0.6", lw=0.8) axes[1].set_xlabel("parallel shift (bp)") axes[1].set_ylabel("value to fixed payer per 100") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.035 seconds) .. _sphx_glr_download_api_gallery_fixed_income_swaps_plot_02_interest_rate_swap.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/fixed_income/swaps/plot_02_interest_rate_swap.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_interest_rate_swap.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_interest_rate_swap.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_interest_rate_swap.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_