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

% Copyright 2019 The MathWorks, Inc.