%% Price a FixedBondOption Instrument on a Stepped FixedBond Using Hull-White Model and Hull-White Tree Pricer
% This example shows the workflow to price a FixedBondOption instrument on a stepped FixedBond instrument when you use a HullWhite model and an IRTree pricing method.
%% Create Stepped FixedBond Instrument Object
% Use fininstrument to create a stepped FixedBond instrument object as the underlying bond.

Maturity = datetime(2027,1,1);
Period = 1;
CDates = datetime([2022,1,1 ; 2027,1,1]);
CRates = [.022; .027];
CouponRate = timetable(CDates,CRates);

SBond = fininstrument("FixedBond",'Maturity',Maturity,'CouponRate',CouponRate,'Period',Period,'Name',"stepped_bond_instrument") 

%% Create FixedBondOption Instrument Object
% Use fininstrument to create a FixedBondOption instrument object with European exercise.

FixedBOption = fininstrument("FixedBondOption",'ExerciseDate',datetime(2026,1,1),'Strike',90,'Bond',SBond,'OptionType',"call",'ExerciseStyle',"european",'Name',"fixed_bond_option_european")

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

Settle = datetime(2018,1,1);
ZeroTimes = calyears(1:10)';
ZeroRates = [0.0055 0.0063 0.0071 0.0083 0.0099 0.0131 0.0178 0.0262 0.0343 0.0387]';
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.15;
AlphaCurve = 0.03;

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)
HWTreePricer.Tree

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

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

% Copyright 2019 The MathWorks, Inc.