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

Maturity = datetime(2024,1,1);
Period = 1;
VBond = fininstrument("FixedBond",'Maturity', Maturity,'CouponRate', 0.025,'Period',Period) 

%
%% 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 HullWhite Model Object
% Use finmodel to create a HullWhite model object.

VolCurve = 0.01;
AlphaCurve = 0.1;

HWModel = finmodel("HullWhite",'alpha',AlphaCurve,'sigma',VolCurve);

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

HWTreePricer = finpricer("IRTree",'Model',HWModel,'DiscountCurve',ZeroCurve,'TreeDates',ZeroDates)

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

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

% Copyright 2019 The MathWorks, Inc.