%% Price Amortizing Cap Instrument Using Black Model and Black Pricer
% This example shows the workflow to price an amortizing Cap instrument when you use a Black model and a Black pricing method.
%% Create Cap Instrument Object
% Use fininstrument to create an amortizing Cap instrument object.

CADates = [datetime(2020,9,1) ; datetime(2023,9,1)];
CAPrincipal = [100; 85];
Principal = timetable(CADates,CAPrincipal);

CapOpt = fininstrument("Cap",'Maturity',datetime(2023,9,1),'Strike',0.015,'Principal',Principal,'Name',"cap_amortizing_option")

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

BlackModel = finmodel("Black",'Volatility',0.2)

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

Settle = datetime(2018,9,1);
Type = 'zero';
ZeroTimes = [calyears([1 2 3 4 5 7 10])]';
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168]';
ZeroDates = Settle + ZeroTimes;
            
myRC = ratecurve('zero',Settle,ZeroDates,ZeroRates);

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

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

%% Price Cap Instrument
% Use price to compute the price for the Cap instrument.

Price = price(outPricer,CapOpt)

% Copyright 2019 The MathWorks, Inc.