%% Use a Svensson Function to Fit Bond Market Data
% This example shows how to use a Svensson function to fit bond market data.

Settle = datenum('15-Apr-2014'); 
Maturity = datemnth(Settle,12*[1 2 3 5 7 10 20 30]'); 

CleanPrice = [100.1 100.1 100.2 99.0 101.8 99.2 101.7 100.2]'; 
CouponRate = [0.0200 0.0275 0.035 0.042 0.0475 0.0525 0.055 0.052]'; 
Instruments = [repmat(Settle,size(Maturity)) Maturity CleanPrice CouponRate]; 
PlottingPoints = datemnth(Settle,1:360); 
Yield = bndyield(CleanPrice,CouponRate,Settle,Maturity); 

SvenssonModel = IRFunctionCurve.fitSvensson('Zero',Settle,Instruments); 

SvenssonModel.Parameters 

% create the plot
plot(PlottingPoints, getParYields(SvenssonModel, PlottingPoints),'g') 
hold on 
scatter(Maturity,Yield,'black') 
datetick('x') 
legend({'Svensson Fitted Curve','Yields'},'location','best')

% Copyright 2015 The MathWorks, Inc.