%% Price Amortizing Fixed Bond Instrument Using ratecurve and Discount Pricer
% This example shows the workflow to price a amortizing FixedBond instrument when you use a ratecurve and a Discount pricing method.
%% Create FixedBond Instrument Object
% Use fininstrument to create a amortizing FixedBond instrument object.

Maturity = datetime(2024,1,1);
Period = 1;
ADates = datetime([2020,1,1 ; 2024,1,1]);
APrincipal = [100; 85];
Principal = timetable(ADates,APrincipal);
Bondamort = fininstrument("FixedBond",'Maturity',Maturity,'CouponRate',0.025,'Period',Period,'Principal',Principal)  

%
%% Create ratecurve Object
% Create a ratecurve object using ratecurve.

Settle = datetime(2018,1,1);
ZeroTimes = calyears(1:10)';
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307]';
ZeroDates = Settle + ZeroTimes;
Compounding = 1;
ZeroCurve = ratecurve("zero",Settle,ZeroDates,ZeroRates, "Compounding",Compounding);

%% Create Discount Pricer Object
% Use finpricer to create a Discount pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

outPricer = finpricer("Discount",'DiscountCurve',ZeroCurve)

%% Price FixedBond Instrument
% Use price to compute the price and sensitivities for the vanilla FixedBond instrument.

[Price, outPR] = price(outPricer,Bondamort,["all"])
outPR.Results

% Copyright 2019 The MathWorks, Inc.