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

FloatB = fininstrument("FloatBond",'Maturity',datetime(2020,9,15),'Spread',0.9)

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

Settle = datetime(2019,9,15);
Type = "zero";
ZeroTimes = [calmonths(6) calyears([1 2 3 4 5 7 10 20 30])]';
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307]';
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.02,'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 FloatBond Instrument
% Use price to compute the price and sensitivities for the floatbond instrument.

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

% Copyright 2019 The MathWorks, Inc.