Title: | Smith-Wilson Yield Curve Construction |
---|---|
Description: | Constructs a yield curve by the Smith-Wilson method from a table of libor and swap rates. Now updated to take bond coupons and prices in the same table. |
Authors: | Phil Joubert [aut, cre] |
Maintainer: | Phil Joubert <[email protected]> |
License: | GPL-3 |
Version: | 1.1.1 |
Built: | 2025-03-10 02:31:48 UTC |
Source: | https://github.com/cran/SmithWilsonYieldCurve |
A package to fit yield curves using the Smith-Wilson method
The main function exposed in this package is fFitSmithWilsonYieldCurve, which takes market data in the form of a vector of cashflow times, a matrix of cashflows and a vector of market prices. It returns an object of class "SmithWilsonYieldCurve".
A convenience function fFitSmithWilsonYieldCurveToInstruments takes a dataframe containing market instrument data as type, tenor, frequency and rate. It extracts the required vectors and matrices and then calls fFitSmithWilsonYieldCurve.
Objects of class SmithWilsonYieldCurve are a list, the first element of which is a function P(t), which returns the zero coupon bond price of the fitted curve at time t.
Phil Joubert [email protected]
Smith A. and Wilson, T. - "Fitting Yield curves with long Term Constraints" (2001)
dfInstruments <- data.frame(c("SWAP", "SWAP"), c(1,10), c(1,1), c(0.025, 0.05)) colnames( dfInstruments ) <- c( "Type", "Tenor", "Frequency", "Rate" ) Curve <- fFitSmithWilsonYieldCurveToInstruments( dfInstruments, 0.04, 0.1 ) plot( Curve )
dfInstruments <- data.frame(c("SWAP", "SWAP"), c(1,10), c(1,1), c(0.025, 0.05)) colnames( dfInstruments ) <- c( "Type", "Tenor", "Frequency", "Rate" ) Curve <- fFitSmithWilsonYieldCurveToInstruments( dfInstruments, 0.04, 0.1 ) plot( Curve )
Returns the matrix of cashflows for the list of instruments
fCreateCashflowMatrix(dfInstruments)
fCreateCashflowMatrix(dfInstruments)
dfInstruments |
A set of market instruments as a dataframe with columns Type, Tenor, Frequency and Rate with Type in (LIBOR, SWAP, BOND), Tenor the instrument maturity in years and rate the rate per annum |
Creates a J x J matrix [ w(u_i,u_j) ] where J is the number of cashflow times in the calibration set
fCreateKernelMatrix(times, fKernel)
fCreateKernelMatrix(times, fKernel)
times |
a vector of cashflow times |
fKernel |
a kernel to apply (a function of times x times returning a matrix ) |
Assumes that LIBOR tenor is in days, with 365 days per year. Assumes that SWAPs are semi-annual Returns a vector of all unique cashflow times in years
fCreateTimeVector(dfInstruments)
fCreateTimeVector(dfInstruments)
dfInstruments |
A dataframe of instuments with at least columns Type and Tenor |
Solve for the vector xi of kernel weights
fFitKernelWeights(CashflowMatrix, KernelFunctionMatrix, MarketValueVector, BaseZeroVector)
fFitKernelWeights(CashflowMatrix, KernelFunctionMatrix, MarketValueVector, BaseZeroVector)
CashflowMatrix |
A matrix of all cashflows, instruments in rows, times in columns |
KernelFunctionMatrix |
A matrix of kernel function values |
MarketValueVector |
A vector of market values of the insturments |
BaseZeroVector |
A vector of "base" values for the zeros |
Constructs the SmithWilson ZCB function based on the given market inputs and parameter choices
fFitSmithWilsonYieldCurve( TimesVector, CashflowMatrix, MarketValueVector, ufr, alpha )
fFitSmithWilsonYieldCurve( TimesVector, CashflowMatrix, MarketValueVector, ufr, alpha )
TimesVector |
A vector of all cashflow times |
CashflowMatrix |
A matrix of all cashflows, instruments in rows, times in columns |
MarketValueVector |
A vector of market values of the insturments |
ufr |
The Ultimate Forward Rate (UFR) of the Smith-Wilson kernel |
alpha |
The rate of reversion of forward rates to the UFR in the Smith-Wilson kernel |
a list containing:
"P" a function of time which gives the ZCB price to that term
"xi" the vector of weights applied to the kernel functions to obtain the ZCB price
"K" the (compound) kernel vector
Constructs the SmithWilson ZCB function based on the given market inputs and parameter choices. Primarily a convenience wrapper around other package functions
fFitSmithWilsonYieldCurveToInstruments(InstrumentSet, ufr, alpha)
fFitSmithWilsonYieldCurveToInstruments(InstrumentSet, ufr, alpha)
InstrumentSet |
A set of market instruments as a dataframe with columns
|
ufr |
The Ultimate Forward Rate (UFR) of the Smith-Wilson kernel |
alpha |
The rate of reversion of forward rates to the UFR in the Smith-Wilson kernel |
a list containing:
"P" a function of time which gives the ZCB price to that term
"xi" the vector of weights applied to the kernel functions to obtain the ZCB price
"K" the (compound) kernel vector
Constructs the ZCB function based on the given market inputs and a specific kernel and base function
fFitYieldCurve(TimesVector, CashflowMatrix, MarketValueVector, fKernel, fBase)
fFitYieldCurve(TimesVector, CashflowMatrix, MarketValueVector, fKernel, fBase)
TimesVector |
A vector of all cashflow times |
CashflowMatrix |
A matrix of all cashflows, instruments in rows, times in columns |
MarketValueVector |
A vector of market values of the insturments |
fKernel |
a function of two times used as the Kernel "basis" function |
fBase |
a function giving the base level of the curve |
a list comprising elements: a function of time which gives the ZCB price to that time
Gets the cashflow schedule for a bond
fGetCashflowsBond(dfInstrument)
fGetCashflowsBond(dfInstrument)
dfInstrument |
A market instrument as a dataframe with columns Frequency, Tenor and Rate with Type in (LIBOR, SWAP), Tenor the instrument maturity in years and rate the rate per annum |
Gets the cashflow schedule for a LIBOR agreement
fGetCashflowsLibor(dfInstrument)
fGetCashflowsLibor(dfInstrument)
dfInstrument |
A set of market instruments as a dataframe with columns Type, Tenor and Rate with Type in (LIBOR, SWAP), Tenor the instrument maturity in years and rate the rate per annum |
Gets the cashflow schedule for a swap
fGetCashflowsSwap(dfInstrument)
fGetCashflowsSwap(dfInstrument)
dfInstrument |
A set of market instruments as a dataframe with columns Type, Tenor and Rate with Type in (LIBOR, SWAP), Tenor the instrument maturity in years and rate the rate per annum |
Extract the payment dates of a Bond in years
fGetTimesBond(dfInstrument)
fGetTimesBond(dfInstrument)
dfInstrument |
A dataframe of an instrument with at least columns Frequency and Tenor |
Extract the payment date of a LIBOR agreement in years
fGetTimesLibor(dfInstrument)
fGetTimesLibor(dfInstrument)
dfInstrument |
A dataframe of instuments with at least columns Type and Tenor |
Extract the payment dates of a Swap agreement in years
fGetTimesSwap(dfInstrument)
fGetTimesSwap(dfInstrument)
dfInstrument |
A dataframe of instuments with at least columns Type and Tenor |
Acts as a kernel for regression
fWilson(t, u, ufr, alpha)
fWilson(t, u, ufr, alpha)
t |
a time |
u |
another time |
ufr |
the ultimate forward rate |
alpha |
the spead of reversion to the ultimate forward rate |
Plot generic for SmithWilsonYieldCurve objects
## S3 method for class 'SmithWilsonYieldCurve' lines(x, y, ..., aspect = c("cts", "zero"))
## S3 method for class 'SmithWilsonYieldCurve' lines(x, y, ..., aspect = c("cts", "zero"))
x |
An object of class SmithWilsonYieldCurve or a vector of terms to evaluate the curve at |
y |
Optionally an object of class SmithWilsonYieldCurve |
... |
other arguments to pass to the default lines function |
aspect |
either "cts" for continously compounded spot rates, or "zero" for ZCB prices |
No return value, called for side effect of drawing a graph of the curve
Plot generic for SmithWilsonYieldCurve objects
## S3 method for class 'SmithWilsonYieldCurve' plot(x, y, ..., aspect = c("cts", "zero"))
## S3 method for class 'SmithWilsonYieldCurve' plot(x, y, ..., aspect = c("cts", "zero"))
x |
An object of class SmithWilsonYieldCurve or a vector of terms to evaluate the curve at |
y |
Optionally an object of class SmithWilsonYieldCurve |
... |
other arguments to pass to the default plot function |
aspect |
either "cts" for continously compounded spot rates, or "zero" for ZCB prices |
No return value, called for side effect of drawing a graph of the curve
Plot generic for SmithWilsonYieldCurve objects
## S3 method for class 'SmithWilsonYieldCurve' points(x, y, ..., aspect = c("cts", "zero"))
## S3 method for class 'SmithWilsonYieldCurve' points(x, y, ..., aspect = c("cts", "zero"))
x |
An object of class SmithWilsonYieldCurve or a vector of terms to evaluate the curve at |
y |
Optionally an object of class SmithWilsonYieldCurve |
... |
other arguments to pass to the default plot function |
aspect |
either "cts" for continously compounded spot rates, or "zero" for ZCB prices |
No return value, called for side effect of drawing a graph of the curve