%% Price Option Embedded Fixed Bond Instruments Using Hull-White Model and IRTree Pricer
% This example shows the workflow to price American, European, and Bermudan exercise styles for three callable OptionEmbeddedFixedBond instruments 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 three OptionEmbeddedFixedBond instrument objects with the different exercise styles.

Maturity = datetime(2024,1,1);

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

CallableBondBermudan = fininstrument("OptionEmbeddedFixedBond",'Maturity',Maturity,...
                              'CouponRate',0.025,'Period',Period, ...
                              'CallSchedule',CallSchedule,'CallExerciseStyle', "bermudan")
% Option embedded bond (American callable bond)
Strike = 100;
ExerciseDates = datetime(2024,1,1);
CallSchedule =  timetable(ExerciseDates,Strike,'VariableNames',{'Strike Schedule'}); 
Period = 1;

CallableBondAmerican = fininstrument("OptionEmbeddedFixedBond",'Maturity',Maturity,...
                              'CouponRate',0.025,'Period', Period, ...
                              'CallSchedule',CallSchedule,'CallExerciseStyle',"american")
% Option embedded bond (European callable bond)
Strike = 100;
ExerciseDates = datetime(2024,1,1);
CallSchedule =  timetable(ExerciseDates,Strike,'VariableNames',{'Strike Schedule'}); 
Period = 1;

CallableBondEuropean = fininstrument("OptionEmbeddedFixedBond",'Maturity',Maturity,...
                              'CouponRate',0.025,'Period',Period, ...
                              'CallSchedule',CallSchedule)                          

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

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

% Copyright 2020 The MathWorks, Inc.