.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated_examples\economic\plot_ex4_g2pp_rate_fan.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_examples_economic_plot_ex4_g2pp_rate_fan.py: G2++ short rate and 10-year yield =================================== Fan charts of the short rate and of the 10-year yield in the scenarios that :mod:`~economic.BasicG2PP` generates from ``g2pp_input.xlsx``. The blue bands are percentiles over the stochastic scenarios, around their median. The orange line is the certainty-equivalent (CE) scenario, scenario 0, which follows the initial forward curve. .. seealso:: * :mod:`~economic.BasicG2PP.G2PP` in :mod:`~economic.BasicG2PP` * :doc:`/libraries/economic/g2pp-simulation` notebook in the :mod:`~economic` library .. GENERATED FROM PYTHON SOURCE LINES 15-60 .. image-sg:: /generated_examples/economic/images/sphx_glr_plot_ex4_g2pp_rate_fan_001.png :alt: Short rate, 10-year yield, annually compounded :srcset: /generated_examples/economic/images/sphx_glr_plot_ex4_g2pp_rate_fan_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import modelx as mx import numpy as np from matplotlib.lines import Line2D from matplotlib.patches import Patch from matplotlib.ticker import PercentFormatter # Chart style of the G2++ notebooks: blue for the stochastic scenarios, orange for CE BLUE, ORANGE, INK_2, GRID, AXIS = "#2a78d6", "#eb6834", "#52514e", "#e1e0d9", "#c3c2b7" plt.rcParams.update({ "axes.edgecolor": AXIS, "axes.grid": True, "grid.color": GRID, "axes.spines.top": False, "axes.spines.right": False, "axes.titlelocation": "left", "axes.labelcolor": INK_2, "xtick.color": AXIS, "ytick.color": AXIS, "xtick.labelcolor": INK_2, "ytick.labelcolor": INK_2, "legend.frameon": False, }) BANDS = [(1, 99), (5, 95), (25, 75)] # nested percentile bands WASH = 0.10 # opacity of each band g2pp = mx.read_model("BasicG2PP").G2PP years = np.arange(g2pp.step_size() + 1) / 12 fig, axes = plt.subplots(1, 2, figsize=(10, 4), sharey=True) for ax, paths, title in [(axes[0], g2pp.short_rate_paths(), "Short rate"), (axes[1], g2pp.spot_rate_paths(120), "10-year yield, annually compounded")]: stochastic = paths[1:] for lo, hi in BANDS: ax.fill_between(years, np.percentile(stochastic, lo, axis=0), np.percentile(stochastic, hi, axis=0), color=BLUE, alpha=WASH, linewidth=0) ax.plot(years, np.median(stochastic, axis=0), color=BLUE, linewidth=2) ax.plot(years, paths[0], color=ORANGE, linewidth=2) ax.axhline(0, color=AXIS, linewidth=1) ax.set_title(title) ax.set_xlabel("years from the valuation date") ax.set_xlim(0, years[-1]) ax.yaxis.set_major_formatter(PercentFormatter(1.0, decimals=0)) handles = [Patch(color=BLUE, alpha=1 - (1 - WASH) ** k, linewidth=0, label=f"{lo} to {hi} percentile") for k, (lo, hi) in enumerate(BANDS, start=1)] handles += [Line2D([], [], color=BLUE, linewidth=2, label="median"), Line2D([], [], color=ORANGE, linewidth=2, label="CE scenario")] fig.legend(handles=handles, loc="lower center", ncols=5) fig.tight_layout(rect=(0, 0.08, 1, 1)) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.089 seconds) .. _sphx_glr_download_generated_examples_economic_plot_ex4_g2pp_rate_fan.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_ex4_g2pp_rate_fan.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_ex4_g2pp_rate_fan.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_ex4_g2pp_rate_fan.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_