%% Price Option Embedded Fixed Bond Option Instrument Using Hull-White Model and IRMonteCarlo Pricer
% This example shows the workflow to price an OptionEmbeddedFixedBondOption instrument when using a HullWhite model and an IRMonteCarlo pricing method.
%% Create ratecurve Object
% Create a ratecurve object using ratecurve.

Settle = datetime(2019,1,1);
Type = 'zero';
ZeroTimes = [calmonths(6) calyears([1 2 3 4 5 7 10 20 30])]';
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307]';
ZeroDates = Settle + ZeroTimes;

myRC = ratecurve('zero',Settle,ZeroDates,ZeroRates)

%% Create OptionEmbeddedFixedBondOption Instrument Object
% Use fininstrument to create an OptionEmbeddedFixedBondOption instrument object.

% Option embedded bond (European callable bond)
Maturity = datetime(2022,9,15);
Strike = 100;
ExerciseDates = datetime(2024,1,1);
CallSchedule = timetable(datetime(2020,3,15), 50);
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.

HullWhiteModel = finmodel("HullWhite",'Alpha',0.32,'Sigma',0.49)

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

outPricer = finpricer("IRMonteCarlo",'Model',HullWhiteModel,'DiscountCurve',myRC,'SimulationDates',datetime(2019,3,15)+calmonths(0:6:48)')

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

[Price,outPR] = price(outPricer,CallableBondEuropean,["all"])
outPR.Results

% Copyright 2021 The MathWorks, Inc.