%% Price Multiple Float Bond Option Instruments Using Hull-White Model and IRTree Pricer
% This example shows the workflow to price multiple FloatBondOption instruments when you use a HullWhite model and an IRTree pricing method.
%% Create FloatBond Instrument Object
% Use fininstrument to create a FloatBond instrument object as the underlying bond.

BondInst = fininstrument("FloatBond",'Maturity',datetime(2030,9,15),'Spread',0.021,'Name',"bond_instrument")

%% Create FloatBondOption Instrument Objects
% Use fininstrument to create a FloatBondOption instrument object with European exercise for three Float Bond Option instruments.

FloatBOptionEuro = fininstrument("FloatBondOption",'ExerciseDate',datetime([2030,9,15 ; 2029,09,15 ; 2028,09,15]),'Strike',[98 ; 99 ; 100],'Bond',BondInst,'OptionType',"call",'ExerciseStyle',"european",'Name',"float_bond_option_european")

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

Settle = datetime(2024,9,15);
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.01,'Sigma',0.05)

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

CFdates = cfdates(Settle, BondInst.Maturity, BondInst.Reset, BondInst.Basis);
HWTreePricer = finpricer("IRTree",'Model',HullWhiteModel,'DiscountCurve',myRC,'TreeDates',CFdates')
HWTreePricer.Tree

%% Price FixedBondOption Instruments
% Use price to compute the prices and sensitivities for the FixedBondOption instruments.

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

% Copyright 2021 The MathWorks, Inc.