Main Content

fitSmoothingSpline

Fit smoothing spline to bond market data

Description

example

CurveObj= IRFunctionCurve.fitSmoothingSpline(Type,Settle,Instruments,Lambdafun)fits a smoothing spline to market data for a bond.

Note

You must have a license for Curve Fitting Toolbox™ software to use thefitSmoothingSplinemethod.

example

CurveObj= IRFunctionCurve.fitSmoothingSpline(___,Name,Value)adds optional name-value pair arguments.

Examples

collapse all

This example shows how to use afitSmoothingSplinefunction to fit market data for a bond.

Settle = repmat(datenum('30-Apr-2008'),[6 1]); Maturity = [datenum('07-Mar-2009');datenum('07-Mar-2011');...datenum('07-Mar-2013');datenum('07-Sep-2016');...datenum('07-Mar-2025');datenum('07-Mar-2036')]; CleanPrice = [100.1;100.1;100.8;96.6;103.3;96.3]; CouponRate = [0.0400;0.0425;0.0450;0.0400;0.0500;0.0425]; Instruments = [Settle Maturity CleanPrice CouponRate]; PlottingPoints = datenum('07-Mar-2009'):180:datenum('07-Mar-2036'); Yield = bndyield(CleanPrice,CouponRate,Settle,Maturity);% Use the AUGKNT function to construct the knots for a cubic spline at% every 5 years.CustomKnots = augknt(0:5:30,4); SmoothingModel = IRFunctionCurve.fitSmoothingSpline('Zero',datenum('30-Apr-2008'),...Instruments,@(t) 1000,'knots', CustomKnots);% Create the plot.plot(PlottingPoints, getParYields(SmoothingModel, PlottingPoints),'b') holdonscatter(Maturity,Yield,'black') datetick('x')

图包含一个坐标轴对象。The axes object contains 2 objects of type line, scatter.

This example shows for to usefitSmoothinSplinefunction to fit the interest-rate curve and model theLambdafunpenalty function.

First, load the data.

loadukdata20080430

Convert the repo rates to be equivalent zero coupon bonds.

RepoCouponRate = repmat(0,大小(RepoRates));RepoPrice = bndprice(RepoRates, RepoCouponRate, RepoSettle, RepoMaturity);

Aggregate the data.

Settle = [RepoSettle;BondSettle]; Maturity = [RepoMaturity;BondMaturity]; CleanPrice = [RepoPrice;BondCleanPrice]; CouponRate = [RepoCouponRate;BondCouponRate]; Instruments = [Settle Maturity CleanPrice CouponRate]; InstrumentPeriod = [repmat(0,6,1);repmat(2,31,1)]; CurveSettle = datenum('30-Apr-2008');

Choose the parameters for theLambdafuninput argument.

L = 9.2; S = -1; mu = 1;

Define theLambdafunpenalty function.

lambdafun = @(t) exp(L - (L-S)*exp(-t/mu)); t = 0:.1:25; y = lambdafun(t); figure semilogy(t,y); title('Penalty Function for VRP Approach') ylabel('Penalty') xlabel('Time')

图包含一个坐标轴对象。坐标轴对象with title Penalty Function for VRP Approach contains an object of type line.

Use thefitSmoothinSplinefunction to fit the interest-rate curve and model theLambdafunpenalty function.

VRPModel = IRFunctionCurve.fitSmoothingSpline('Forward',CurveSettle,...Instruments,lambdafun,'Compounding',-1,'InstrumentPeriod',InstrumentPeriod)
VRPModel = Type: Forward Settle: 733528 (30-Apr-2008) Compounding: -1 Basis: 0 (actual/actual)

Plot the smoothing spline interest-rate curve for the forward rates.

PlottingDates = CurveSettle+20:30:CurveSettle+365*25; TimeToMaturity = yearfrac(CurveSettle,PlottingDates); VRPForwardRates = getForwardRates(VRPModel, PlottingDates); figure;plot(TimeToMaturity,VRPForwardRates) title('Smoothing Spline Model of UK Instantaneous Nominal Forward Curve')

图包含一个坐标轴对象。坐标轴对象with title Smoothing Spline Model of UK Instantaneous Nominal Forward Curve contains an object of type line.

Input Arguments

collapse all

Type of interest-rate curve for a bond, specified by using a scalar character vector.

Data Types:char

结算日期利率曲线,指定的强g a scalar date character vector or serial date number.

Data Types:double|char

Instruments, specified using anN-by-4data matrix where the first column isSettledate, the second column isMaturity, the third column is the clean price, and the fourth column is aCouponRatefor the bond.

Data Types:double

Penalty function, specified using a function handle. The penalty function that takes as its input time and returns a penalty value. The function handle for the penalty function takes one numeric input (time-to-maturity) and returns one numeric output (penalty to be applied to the curvature of the spline). For more information on defining a function handle, see the MATLAB®Programming Fundamentals documentation.

Note

The smoothing spline represents the forward curve. The spline is penalized for curvature by specifying a penalty function. This fit can only be done with aFitTypeofDurationWeightedPrice.

Data Types:function_handle

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:CurveObj = IRFunctionCurve.fitSmoothingSpline('Zero',datenum('30-Apr-2008'),Instruments,@(t) 1000,'knots',CustomKnots)

Name-Value Pair Arguments for All Bond Instruments

collapse all

Compounding frequency per-year for theIRFunctionCurveobject, specified as the comma-separated pair consisting of'Compounding'and a scalar numeric using one of the supported values:

  • −1= Continuous compounding

  • 0= Simple interest (no compounding)

  • 1= Annual compounding

  • 2= Semiannual compounding

  • 3= Compounding three times per year

  • 4= Quarterly compounding

  • 6= Bimonthly compounding

  • 12= Monthly compounding

Data Types:double

Day count basis of the interest-rate curve, specified as the comma-separated pair consisting of'Basis'and a scalar integer.

  • 0 — actual/actual

  • 1 — 30/360 (SIA)

  • 2 — actual/360

  • 3 — actual/365

  • 4 — 30/360 (PSA)

  • 5 — 30/360 (ISDA)

  • 6 — 30/360 (European)

  • 7 — actual/365 (Japanese)

  • 8 — actual/actual (ICMA)

  • 9 — actual/360 (ICMA)

  • 10 — actual/365 (ICMA)

  • 11 — 30/360E (ICMA)

  • 12 — actual/365 (ISDA)

  • 13 — BUS/252

For more information, seeBasis.

Data Types:double

Name-Value Pair Arguments for Each Bond Instrument

collapse all

Coupons per year for the bond, specified as the comma-separated pair consisting of'InstrumentPeriod'and a scalar numeric value.

Data Types:double

Day count basis of the bond, specified as the comma-separated pair consisting of'InstrumentBasis'and a scalar integer.

  • 0 — actual/actual

  • 1 — 30/360 (SIA)

  • 2 — actual/360

  • 3 — actual/365

  • 4 — 30/360 (PSA)

  • 5 — 30/360 (ISDA)

  • 6 — 30/360 (European)

  • 7 — actual/365 (Japanese)

  • 8 — actual/actual (ICMA)

  • 9 — actual/360 (ICMA)

  • 10 — actual/365 (ICMA)

  • 11 — 30/360E (ICMA)

  • 12 — actual/365 (ISDA)

  • 13 — BUS/252

Note

InstrumentBasisdistinguishes a bond instrument'sBasisvalue from the interest-rate curve'sBasisvalue.

For more information, seeBasis.

Data Types:double

End-of-month rule, specified as the comma-separated pair consisting of'InstrumentEndMonthRule'and a logical value. This rule applies only whenMaturityis an end-of-month date for a month having 30 or fewer days.

  • 0= ignore rule, meaning that a bond's coupon payment date is always the same numerical day of the month.

  • 1=setrule on (default), meaning that a bond's coupon payment date is always the last actual day of the month.

Data Types:logical

Instrument issue date, specified as the comma-separated pair consisting of'InstrumentIssueDate'and a scalar date character vector or serial date number.

Data Types:char|double

Date when a bond makes its first coupon payment (used when bond has an irregular first coupon period), specified as the comma-separated pair consisting of'InstrumentFirstCouponDate'and a scalar date character vector or serial date number. WhenInstrumentFirstCouponDateandInstrumentLastCouponDateare both specified,InstrumentFirstCouponDatetakes precedence in determining the coupon payment structure. If you do not specify aInstrumentFirstCouponDate, the cash flow payment dates are determined from other inputs.

Data Types:char|double

Last coupon date of a bond before the maturity date (used when bond has an irregular last coupon period), specified as the comma-separated pair consisting of'InstrumentLastCouponDate'and a scalar date character vector or serial date number. In the absence of a specifiedInstrumentFirstCouponDate, a specifiedInstrumentLastCouponDatedetermines the coupon structure of the bond. The coupon structure of a bond is truncated at theInstrumentLastCouponDate, regardless of where it falls, and is followed only by the bond's maturity cash flow date. If you do not specify aInstrumentLastCouponDate, the cash flow payment dates are determined from other inputs.

Data Types:char|double

Face or par value, specified as the comma-separated pair consisting of'InstrumentFace'and a scalar numeric.

Data Types:double

Note

When usingInstrumentname-value pairs, you can specify simple interest for a bond by specifying theInstrumentPeriodvalue as0. IfInstrumentBasisandInstrumentPeriodare not specified for a bond, the following default values are used:InstrumentBasisis0(act/act) andInstrumentPeriodis2.

Output Arguments

collapse all

Smoothing spline curve model, returned as a structure.

Algorithms

The term structure can be modeled with a spline — specifically, one way to model the term structure is by representing the forward curve with a cubic spline. To ensure that the spline is sufficiently smooth, a penalty is imposed relating to the curvature (second derivative) of the spline:

where the first term is the difference between the observed pricePand the predicted price, P ^ , (weighted by the bond's duration,D) summed over all bonds in our data set and the second term is the penalty term (where λ is a penalty function andfis the spline).

See [3], [4], [5] below.

There have been different proposals for the specification of the penalty function λ. One approach, advocated by [4], and currently used by the UK Debt Management Office, is a penalty function of the following form:

References

[1] Nelson, C.R., Siegel, A.F. “Parsimonious modelling of yield curves.”Journal of Business.Vol. 60, 1987, pp 473–89.

[2] Svensson, L.E.O.“Estimating and interpreting forward interest rates: Sweden 1992-4.”International Monetary Fund, IMF Working Paper, 1994/114.

[3] Fisher, M., Nychka, D., Zervos, D.“Fitting the term structure of interest rates with smoothing splines.”Board of Governors of the Federal Reserve System, Federal Reserve Board Working Paper 1995-1.

[4] Anderson, N., Sleath, J.“New estimates of the UK real and nominal yield curves.”Bank of England Quarterly Bulletin, November, 1999, pp 384–92.

[5] Waggoner, D.“Spline Methods for Extracting Interest Rate Curves from Coupon Bond Prices.”Federal Reserve Board Working Paper 1997–10.

[6]“Zero-coupon yield curves: technical documentation.”BIS Papers No. 25, October 2005.

[7] Bolder, D.J., Gusba, S.“Exponentials, Polynomials, and Fourier Series: More Yield Curve Modelling at the Bank of Canada.”Working Papers 2002–29, Bank of Canada.

[8] Bolder, D.J., Streliski, D.“Yield Curve Modelling at the Bank of Canada.”Technical Reports 84, 1999, Bank of Canada.

Version History

Introduced in R2008b