%% Price Multiple Option Embedded Fixed Bond Instruments Using Hull-White Model and IRTree Pricer
% This example shows the workflow to price multiple callable OptionEmbeddedFixedBond instruments with Bermudan exercise styles when you use a HullWhite model and an IRTree pricing method.
%
%% 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 OptionEmbeddedFixedBond Instrument Objects
% Use fininstrument to create an OptionEmbeddedFixedBond instrument object for three Option Embedded Fixed Bond instuments.

Maturity = datetime([2025,1,1 ; 2026,1,1 ; 2027,1,1]);

% Option embedded bond (Bermudan callable bond)
Strike = [100 ; 200 ; 300]; 
ExerciseDates = datetime([2022,1,1 ; 2023,1,1 ; 2024,1,1]); 
CallSchedule =  timetable(ExerciseDates,Strike,'VariableNames',{'Strike Schedule'}); 
Period = 1;

CallableBondBermudan = fininstrument("OptionEmbeddedFixedBond",'Maturity',Maturity,...
                              'CouponRate',0.025,'Period', Period, ...
                              'CallSchedule',CallSchedule,'CallExerciseStyle',"Bermudan")  

% When you create multiple OptionEmbeddedFixedBond instruments and use a timetable for CallSchedule, the timetable specification applies to all of the OptionEmbeddedFixedBond instruments. The CallSchedule input argument does not accept an NINST-by-1 cell array of timetables as input.
%% 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 OptionEmbeddedFixedBond Instruments
% Use price to compute the prices and sensitivities for the OptionEmbeddedFixedBond instruments.

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

% Copyright 2021 The MathWorks, Inc.