.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated_examples\smithwilson\plot_smithwilson.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_examples_smithwilson_plot_smithwilson.py: Smith-Wilson extrapolation with various alphas ============================================== This notebook reads in the **smithwilson** model, and extrapolates forward rates using the Smith-Wilson method with various alphas, and draws the forward rates. See :doc:`/projects/smithwilson` for the details of the **smithwilson** model. The source of the input data is Switzerland EIOPA spot rates with LLP 25 years available from the following source. Source: RFR_spot_no_VA tab in EIOPA_RFR_20190531_Term_Structures.xlsx, archived in EIOPA_RFR_20190531.zip, avaialble on `EIOPA's Risk-Free Interest Rate Term Structures web site`_. .. _EIOPA's Risk-Free Interest Rate Term Structures web site: https://wayback.archive-it.org/org-1495/20191229100044/https:/eiopa.europa.eu/regulation-supervision/insurance/solvency-ii-technical-information/risk-free-interest-rate-term-structures .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: default import modelx as mx import pandas as pd .. GENERATED FROM PYTHON SOURCE LINES 27-30 The code below reads the ``smithwilson`` model from *"model"* folder, and assign ``SmithWilson`` space in the model to a global variable named ``space``. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: default space = mx.read_model("model").SmithWilson .. GENERATED FROM PYTHON SOURCE LINES 34-38 The code below is for parametrizing the ``SmithWilson`` space by ``x``. The parameter ``x`` takes integer values, and they can be positive and negative. the alpha in the ``SmithWilson[x]`` space is adjusted from the original alpha by ``x`` times 10%. .. GENERATED FROM PYTHON SOURCE LINES 38-44 .. code-block:: default def parametrize(x): return {"refs": {"alpha": alpha * (1 + 0.1*x)}} space.formula = parametrize .. GENERATED FROM PYTHON SOURCE LINES 45-48 The code below creates the ``ForwardRates`` cells, which calculates extrapolated forward rates from the present values of bond prices. .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: default @mx.defcells def ForwardRates(t): return P(t) / P(t+1) - 1 .. GENERATED FROM PYTHON SOURCE LINES 55-57 The code below plots the extrapolated forward rates with various alphas. .. GENERATED FROM PYTHON SOURCE LINES 57-64 .. code-block:: default d = {"{0:.3}".format(space.alpha * (1 + 0.1*x)): [space[x].ForwardRates[t] for t in range(1, 101)] for x in range(-6, 5)} df = pd.DataFrame(d, index=range(1, 101)) df.plot.line() .. image-sg:: /generated_examples/smithwilson/images/sphx_glr_plot_smithwilson_001.png :alt: plot smithwilson :srcset: /generated_examples/smithwilson/images/sphx_glr_plot_smithwilson_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.739 seconds) .. _sphx_glr_download_generated_examples_smithwilson_plot_smithwilson.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_smithwilson.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_smithwilson.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_