%% Price a Float Bond Option Instrument Using Hull-White Model and IRTree Pricer
% This example shows the workflow to price a FloatBondOption instrument 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 three callable FloatBondOption instrument objects with European, American, and Bermudan exercise.

FloatBOptionEuro = fininstrument("FloatBondOption",'ExerciseDate',datetime(2029,9,15),'Strike',98,'Bond',BondInst,'OptionType',"call",'ExerciseStyle',"european",'Name',"float_bond_option_european")
FloatBOptionAmerican = fininstrument("FloatBondOption",'ExerciseDate',datetime(2029,9,15),'Strike',98,'Bond',BondInst,'OptionType',"call",'ExerciseStyle',"american",'Name',"float_bond_option_american")
FloatBOptionBermudan = fininstrument("FloatBondOption",'ExerciseDate',[datetime(2025,9,15) ; datetime(2029,09,15)],'Strike',[98,100],'Bond',BondInst,'OptionType',"call",'ExerciseStyle',"bermudan",'Name',"float_bond_option_bermudan")

%
%% 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 price and sensitivities for the two FixedBondOption instruments.

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

% Copyright 2020 The MathWorks, Inc.