%% Price Vanilla Floor Instrument Using Hull-White Model and IRTree Pricer
% This example shows the workflow to price a vanilla Floor instrument when using a HullWhite model and an IRTree pricing method.
%% Create Floor Instrument Object
% Use fininstrument to create a Floor instrument object.

FloorOpt = fininstrument("Floor",'Strike',0.03,'Maturity',datetime(2020,1,30),'Reset',4,'Principal',100,'Basis',8,'Name',"floor_option")

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

HullWhiteModel = finmodel("HullWhite",'Alpha',0.01,'Sigma',0.10)

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

Settle = datetime(2018,9,15);
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 IRTree Pricer Object
% Use finpricer to create an IRTree pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

CFdates = cfdates(Settle, FloorOpt.Maturity, FloorOpt.Reset, FloorOpt.Basis);
outPricer = finpricer("IRTree",'Model',HullWhiteModel,'DiscountCurve',myRC,'TreeDates',CFdates')

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

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

% Copyright 2020 The MathWorks, Inc.