Main Content

fitFunction

Custom fit interest-rate curve object to bond market data

Description

CurveObj = fitFunction(Type,Settle,FunctionHandle,Instruments,IRFitOptionsObj) fits a bond to a custom fitting function.

example

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

example

Examples

collapse all

This example shows how to use fitFunction to custom fit 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];
CurveSettle = datenum('30-Apr-2008');
OptOptions = optimoptions('lsqnonlin','display','iter');
functionHandle = @(t,theta) polyval(theta,t);    

CustomModel = IRFunctionCurve.fitFunction('Zero', CurveSettle, ...
functionHandle,Instruments, ...
IRFitOptions([.05 .05 .05],'FitType','price',...
'OptOptions',OptOptions))
                                            Norm of      First-order 
 Iteration  Func-count      Resnorm            step       optimality
     0          4           38036.7                         4.92e+04
     1          8           38036.7              10         4.92e+04      
     2         12           38036.7             2.5         4.92e+04      
     3         16           38036.7           0.625         4.92e+04      
     4         20           38036.7         0.15625         4.92e+04      
     5         24           30741.5       0.0390625         1.72e+05      
     6         28           30741.5        0.078125         1.72e+05      
     7         32           30741.5       0.0195312         1.72e+05      
     8         36           28713.6      0.00488281         2.33e+05      
     9         40           20323.3      0.00976562         9.47e+05      
    10         44           20323.3       0.0195312         9.47e+05      
    11         48           20323.3      0.00488281         9.47e+05      
    12         52           20323.3       0.0012207         9.47e+05      
    13         56           19698.8     0.000305176         1.08e+06      
    14         60             17493     0.000610352            7e+06      
    15         64             17493       0.0012207            7e+06      
    16         68             17493     0.000305176            7e+06      
    17         72           15455.1     7.62939e-05         2.25e+07      
    18         76           15455.1     0.000177499         2.25e+07      
    19         80           13317.1      3.8147e-05         3.18e+07      
    20         84           12865.3     7.62939e-05         7.83e+07      
    21         88           11779.8     7.62939e-05         7.58e+06      
    22         92           11747.6     0.000152588         1.45e+05      
    23         96           11720.9     0.000305176         2.33e+05      
    24        100           11667.2     0.000610352         1.48e+05      
    25        104           11558.6       0.0012207         3.55e+05      
    26        108           11335.5      0.00244141         1.57e+05      
    27        112           10863.8      0.00488281         6.36e+05      
    28        116           9797.14      0.00976562         2.53e+05      
    29        120           6882.83       0.0195312         9.18e+05      
    30        124           6882.83       0.0373993         9.18e+05      
    31        128           3218.45      0.00934981         1.96e+06      
    32        132           612.703       0.0186996         3.01e+06      
    33        136           13.0998       0.0253882         3.05e+06      
    34        140         0.0762922      0.00154002         5.05e+04      
    35        144         0.0731652     3.61103e-06             29.9      
    36        148         0.0731652     6.32308e-08            0.063      

Local minimum possible.

lsqnonlin stopped because the final change in the sum of squares relative to 
its initial value is less than the value of the function tolerance.
CustomModel = 
			 Type: Zero
		   Settle: 733528 (30-Apr-2008)
	  Compounding: 2
			Basis: 0 (actual/actual)

Input Arguments

collapse all

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

Data Types: char

Settle date of interest-rate curve, specified using a scalar serial date number or date character vector.

Data Types: double | char

Function handle that defines the interest-rate curve, specified using a function handle. The function handle takes two numeric vectors (time-to-maturity and a vector of function coefficients) and returns one numeric output (interest rate or discount factor). For more information on defining a function handle, see the MATLAB® Programming Fundamentals documentation.

Data Types: function_handle

Instruments, specified using an N-by-4 data matrix where the first column is Settle date using a serial date number, the second column is Maturity using a serial date number, the third column is the clean price, and the fourth column is a CouponRate for the bond.

Data Types: double

IRFitOptions object, specified using previously created object using IRFitOptions.

Data Types: object

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is 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 enclose Name in quotes.

Example: CurveObj = IRFunctionCurve.fitFunction('Zero',CurveSettle,functionHandle,Instruments,IRFitOptions([.05 .05 .05],'FitType','price','OptOptions',OptOptions))

Name-Value Pair Arguments for All Bond Instruments

collapse all

Compounding frequency per-year for the IRFunctionCurve object, 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 bond, 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, see Basis.

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

InstrumentBasis distinguishes a bond instrument's Basis value from the interest-rate curve's Basis value.

For more information, see Basis.

Data Types: double

End-of-month rule, specified as the comma-separated pair consisting of 'InstrumentEndMonthRule' and a logical value. This rule applies only when Maturity is 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 = set rule 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 serial date number or date character vector.

Data Types: double | char

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 serial date number or date character vector. When InstrumentFirstCouponDate and InstrumentLastCouponDate are both specified, InstrumentFirstCouponDate takes precedence in determining the coupon payment structure. If you do not specify a InstrumentFirstCouponDate, the cash flow payment dates are determined from other inputs.

Data Types: double | char

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 serial date number or date character vector. In the absence of a specified InstrumentFirstCouponDate, a specified InstrumentLastCouponDate determines the coupon structure of the bond. The coupon structure of a bond is truncated at the InstrumentLastCouponDate, regardless of where it falls, and is followed only by the bond's maturity cash flow date. If you do not specify a InstrumentLastCouponDate, the cash flow payment dates are determined from other inputs.

Data Types: double | char

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

Data Types: double

Note

When using Instrument name-value pairs, you can specify simple interest for a bond by specifying the InstrumentPeriod value as 0. If InstrumentBasis and InstrumentPeriod are not specified for a bond, the following default values are used: InstrumentBasis is 0 (act/act) and InstrumentPeriod is 2.

Output Arguments

collapse all

Curve model, returned as a structure.

Version History

Introduced in R2008b