%% Use Black-Karasinski Model and Black-Karasinski Tree Pricer to Price FixedBondOption Instrument
% This example shows the workflow to price a FixedBondOption instrument when you use a BlackKarasinski model and an IRTree pricing method.
%% Create FixedBond Instrument Object
% Use fininstrument to create a FixedBond instrument object as the underlying bond.

BondInst = fininstrument("FixedBond",'Maturity',datetime(2029,9,15),'CouponRate',.024,'Principal',100,'Basis',1,'Period',1,'Name',"fixed_bond")

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

FixedBOption = fininstrument("FixedBondOption",'ExerciseDate',datetime(2025,9,15),'Strike',800,'Bond',BondInst,'OptionType',"put",'ExerciseStyle',"american",'Name',"fixed_bond_option")

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

Settle = datetime(2019,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, 'Basis',5)

%% Create BlackKarasinski Model Object
% Use finmodel to create a BlackKarasinski model object.

BlackKarasinskiModel = finmodel("BlackKarasinski",'Alpha',0.02,'Sigma',0.34)

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

BKTreePricer = finpricer("IRTree",'Model',BlackKarasinskiModel,'DiscountCurve',myRC,'TreeDates',ZeroDates)
BKTreePricer.Tree

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

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

% Copyright 2019 The MathWorks, Inc.