fitNelsonSiegel
Description
fits a Nelson-Siegel model to bond data.outCurve
= fitNelsonSiegel(Settle
,Instruments
,CleanPrice
)
Examples
Fit Nelson-Siegel Model to Bond Market Data
Define the bond data and use fininstrument
to create FixedBond
instrument objects.
Settle = datetime(2017,9,15); Maturity = [datetime(2019,9,15);datetime(2021,9,15);... datetime(2023,9,15);datetime(2026,9,7);... datetime(2035,9,15);datetime(2047,9,15)]; 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]; nInst = numel(CouponRate); Bonds(nInst,1) = fininstrument.FinInstrument; for ii=1:nInst Bonds(ii) = fininstrument("FixedBond",'Maturity',Maturity(ii),... 'CouponRate',CouponRate(ii)); end
Use fitNelsonSiegel
to create a parametercurve
object.
NSModel = fitNelsonSiegel(Settle,Bonds,CleanPrice)
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.
NSModel = parametercurve with properties: Type: "zero" Settle: 15-Sep-2017 Compounding: -1 Basis: 0 FunctionHandle: @(t)fitF(Params,t) Parameters: [3.5087e-08 0.0363 0.0900 16.5823]
Input Arguments
Settle
— Settlement date
datetime scalar | string scalar | date character vector
Settlement date, specified as a scalar datetime, string, or date character vector.
To support existing code, fitNelsonSiegel
also
accepts serial date numbers as inputs, but they are not recommended.
Instruments
— Bond instrument objects
array
Bond instrument objects, specified as an array of bond instruments objects.
Data Types: object
CleanPrice
— Observed market prices
vector
Observed market prices, specified as a vector.
Data Types: double
Output Arguments
outCurve
— Fitted Nelson-Siegel model
parametercurve
object
Fitted Nelson-Siegel model, returned as a parametercurve
object.
Version History
Introduced in R2020aR2022b: Serial date numbers not recommended
Although fitNelsonSiegel
supports serial date numbers,
datetime
values are recommended instead. The
datetime
data type provides flexible date and time
formats, storage out to nanosecond precision, and properties to account for time
zones and daylight saving time.
To convert serial date numbers or text to datetime
values, use the datetime
function. For example:
t = datetime(738427.656845093,"ConvertFrom","datenum"); y = year(t)
y = 2021
There are no plans to remove support for serial date number inputs.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)