%% Price Multiple Vanilla Cap Instruments Using Hull-White Model and Hull-White Pricer
% This example shows the workflow to price multiple vanilla Cap instruments when using a HullWhite model and a HullWhite pricing method.
%% Create Cap Instrument Object
% Use fininstrument to create a Cap instrument object for three Cap instruments.

CapOpt = fininstrument("Cap",'Strike',0.02,'Maturity',datetime([2019,1,30 ; 2019,2,30 ; 2019,3,30]),'Reset',4,'Principal',[100 ; 200 ; 300],'Basis',8,'Name',"cap_option")

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

HullWhiteModel = finmodel("HullWhite",'Alpha',0.62,'Sigma',0.99)

%% 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 HullWhite Pricer Object
% Use finpricer to create a HullWhite pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

outPricer = finpricer("analytic",'Model',HullWhiteModel,'DiscountCurve',myRC)

%% Price Cap Instruments
% Use price to compute the prices for the Cap instruments.

Price = price(outPricer,CapOpt)

% Copyright 2021 The MathWorks, Inc.