Code Monkey home page Code Monkey logo

open-source-modelling / smith_wilson_python Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 191 KB

Implementation of the Smith & Wilson algorithm for interpolation and/or extrapolation of missing interest rates in Python.

Home Page: https://www.eiopa.europa.eu/system/files/2022-09/eiopa-bos-22-409-technical-documentation.pdf

License: MIT License

Python 100.00%
insurance solvency-ii actuarial interpolation extrapolation smith-wilson finance python algorithm

smith_wilson_python's Introduction

๐Ÿ Smith & Wilson algorithm ๐Ÿ


Popular algorithm for interpolating and extrapolating various curves such as bond yields and risk-free rates.

This implementation is based on the Technical documentation of the Methodology to derive EIOPA's risk-free interest rate term structure.

The link is for version published on 12/09/2019. See Section 7.

Problem

When analysing market expectations of future rates, a common approach is to look at fixed income instruments such as government or corporate bonds that mature in the future. In practice, the maturities observable (and liquid) on the market rarely covers all the maturities that are needed.

Solution

This implementation takes as input the available market information, parameters describing the long-term behaviour of the curve and the data on desired (target) maturities for which the yields are needed.

Available market information

  • Observed yields of the Zero-Coupon Bonds (ZCB).
  • Maturity of the observed ZCB.

Parameters

  • Ultimate froward rate ufr represents the rate to which the rate curve will converge as time increases.
  • Convergence speed parameter ฮฑ controls the speed at which the curve converges towards the ufr parameter from the last liquid point (last data point available in the market information input).

Desired output

  • List of maturities for which the SW algorithm will calculate the yields.

Note that this implementation assumes that the yields were calculated on ZCB. This assumption can be easily relaxed in future releases.

The implementation is split in two parts:

  • The available market data and the parameters are used to "calibrate" the algorithm. This returns a calibration vector that can be used to interpolate or extrapolate target maturities. This is done by calibrating the kernel functions. Look at the function SWCalibrate().
  • The yields for ZCB with targeted maturities are Interpolated/extrapolated. Look at the function SWExtrapolate().

The syntax in the functions tries to be consistent with EIOPA technical specifications.

Getting started

Given the data on 6 ZCB with maturities of 1, 2, 4, 5, 6, and 7 years with observed yields 1%, 2%, 3%, 3.2%, 3.5%, and 4% respectively. The user is interested in yields for ZCB at maturities 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, and 20 years. The given calibration for the parameter alpha is 0.15 and the ultimate forward rate is 4%.

import numpy as np
from SWCalibrate import SWCalibrate as SWCalibrate
from SWExtrapolate import SWExtrapolate as SWExtrapolate

# Yields observed on the market
r_Obs = np.transpose(np.array([0.01, 0.02, 0.03, 0.032, 0.035, 0.04])) 

# Maturities of bonds observed on the market
M_Obs = np.transpose(np.array([1, 2, 4, 5, 6, 7]))  

# Ultimate forward rate
ufr = 0.04 

# Convergence speed parameter
alpha = 0.15 

# Targeted maturities for interpolation/extrapolation
M_Target = np.transpose(np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20])) 

# Calibration vector calculation
b = SWCalibrate(r_Obs,M_Obs, ufr, alpha) 

# Calculation of target yields
r_Target = SWExtrapolate(M_Target,M_Obs, b, ufr, alpha)

# Display target yields
print("The interpolated/extrapolated rates are:") 
print(r_Target)

About the example in main.py

Example.py contains a script with an example from EIOPA's own Excel implementation tool (Smith-Wilson Risk-Free Interest Rate Extrapolation Tool 27102015.xlsb ). In this example, the yields are available for ZCB maturing in 1 year, 2 years, ..., 20 years. The output is the curve for up to 65 years.

###Note: To extrapolate the curve, it is enough to know the additional parameters (alpha and ufr), the maturities used for calibration and the vector b*Q. If this is the case, it is not difficult to modify the function SWExtrapolate() to take as input Qb instead of b. An example of such an implementation can be seen in this Jupyter Notebook https://github.com/open-source-modelling/EIOPA_smith_wilson_test. An example of this format is the monthly risk free rate published by the European Insurance and Occupational Pensions Authority Official website.


If you have any suggestions for improving the code/comments etc., please let us know.

smith_wilson_python's People

Contributors

gregorfabjan avatar open-source-modelling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gregorfabjan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.