.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fixed_income/curves/plot_01_lutz_forward_rates.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_curves_plot_01_lutz_forward_rates.py: Lutz: forward rates =================== Friedrich Lutz (1940) read the term structure as a sequence of expected future short rates. The forward rate for the period from :math:`t_1` to :math:`t_2` is what the zero curve locks in today, .. math:: f(t_1, t_2) = \frac{r_2 t_2 - r_1 t_1}{t_2 - t_1}, and each zero rate is the time average of the forwards before it. A rising zero curve therefore has forwards above it, and a falling one has forwards below it. .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from financialkit.fixed_income import ZeroCurve, forward_rates .. GENERATED FROM PYTHON SOURCE LINES 23-25 Hull's Table 4.5 ---------------- .. GENERATED FROM PYTHON SOURCE LINES 25-32 .. code-block:: Python tenors = np.array([1, 2, 3, 4, 5.0]) zeros = np.array([0.03, 0.04, 0.046, 0.05, 0.053]) fwd = forward_rates(tenors, zeros) for T, r, f in zip(tenors, zeros, fwd, strict=True): print(f"year {T:.0f}: zero {100 * r:.2f}% forward for year {T:.0f} {100 * f:.2f}%") .. rst-class:: sphx-glr-script-out .. code-block:: none year 1: zero 3.00% forward for year 1 3.00% year 2: zero 4.00% forward for year 2 5.00% year 3: zero 4.60% forward for year 3 5.80% year 4: zero 5.00% forward for year 4 6.20% year 5: zero 5.30% forward for year 5 6.50% .. GENERATED FROM PYTHON SOURCE LINES 33-35 Forwards above a rising curve, below a falling one -------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 35-48 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4), sharey=True) t = np.arange(1, 11, dtype=float) shapes = {"rising": 0.02 + 0.03 * (1 - np.exp(-t / 3)), "inverted": 0.05 - 0.02 * (1 - np.exp(-t / 2))} for ax, (name, r) in zip(axes, shapes.items(), strict=True): f = forward_rates(t, r) ax.step(np.r_[0, t], 100 * np.r_[f, f[-1]], where="post", label="one-year forwards") ax.plot(t, 100 * r, "o-", label="zero rates") ax.set_title(name) ax.set_xlabel("maturity (years)") axes[0].set_ylabel("rate (%)") axes[0].legend() .. image-sg:: /api/gallery/fixed_income/curves/images/sphx_glr_plot_01_lutz_forward_rates_001.png :alt: rising, inverted :srcset: /api/gallery/fixed_income/curves/images/sphx_glr_plot_01_lutz_forward_rates_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 49-51 Zero rates are time averages of forwards ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: Python curve = ZeroCurve(t, shapes["rising"]) f = forward_rates(t, shapes["rising"]) print("max |average of forwards - zero rate| =", np.abs(np.cumsum(f) / t - curve.zero_rate(t)).max()) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none max |average of forwards - zero rate| = 0.0 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.034 seconds) .. _sphx_glr_download_api_gallery_fixed_income_curves_plot_01_lutz_forward_rates.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/curves/plot_01_lutz_forward_rates.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_lutz_forward_rates.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_lutz_forward_rates.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_lutz_forward_rates.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_