www.gusucode.com > fininst 案例源码程序 matlab代码 > fininst/NelsonSiegelToFitBondMarketDataExample.m

    %% Use the Nelson-Siegel Function to Fit Bond Market Data
% This example shows how to use the Nelson-Siegel function to fit bond
% market data.
%%

% Copyright 2015 The MathWorks, Inc.

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);

NSModel = IRFunctionCurve.fitNelsonSiegel('Zero',datenum('30-Apr-2008'),Instruments);

NSModel.Parameters

% create the plot
plot(PlottingPoints, getParYields(NSModel, PlottingPoints),'r')
hold on
scatter(Maturity,Yield,'black')
datetick('x')