%% Price FixedBond Instrument Using a Hull-White Model and Hull-White Tree Pricer
% This example shows the workflow to price a FixedBond instrument when using a HullWhite model and a IRTree pricing method.
%% Create a FixedBond Instrument Object
% Use fininstrument to create a FixedBond instrument object.

FixB = fininstrument("FixedBond","Maturity",datetime("15-Sep-2029"),"CouponRate",.05, "Period", 1,"Name","fixed_bond_instrument")

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

Settle = datetime('15-Sep-2019');
Type = "zero";
ZeroTimes = [calyears([1:10])]';
ZeroRates = [0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307 0.0310]';
ZeroDates = Settle + ZeroTimes;
 
myRC = ratecurve('zero',Settle,ZeroDates,ZeroRates)

%% Create a HullWhite Model Object
% Use finmodel to create a HullWhite model object.

HullWhiteModel = finmodel("hullwhite",'Alpha',0.052,'Sigma',0.34)

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

HWTreePricer = finpricer("irtree","model",HullWhiteModel,"DiscountCurve",myRC,"TreeDates",ZeroDates)
HWTreePricer.Tree

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

[Price, outPR] = price(HWTreePricer, FixB,["all"])
outPR.Results

% Copyright 2019 The MathWorks, Inc.