%% Price Year-on-Year Inflation-Indexed Swap Instrument Using inflationcurve and Inflation Pricer and Compute Cash Flows
% This example shows the workflow to price a YearYearInflationSwap instrument when you use an inflationcurve object and an Inflation pricing method. Then use inflationCashflows to compute the cash flows for the YearYearInflationSwap instrument.
%% Create ratecurve Object
% Create a ratecurve object using ratecurve.

Settle = datetime(2021,1,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;
ZeroCurve = ratecurve('zero',Settle,ZeroDates,ZeroRates)

%% Create inflationcurve Object
% Create an inflationcurve object using inflationcurve.

BaseDate = datetime(2020,10,1);
InflationTimes = [0 calyears([1 2 3 4 5 7 10 20 30])]';
InflationIndexValues = [100 102 103.5 105 106.8 108.2 111.3 120.1 130.4 150.2]';
InflationDates = BaseDate + InflationTimes;
myInflationCurve = inflationcurve(InflationDates,InflationIndexValues)

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

Maturity = datetime(2025,1,1);
FixedInflationRate = 0.015;
Notional = 2000;

YYInflationSwap = fininstrument("YearYearInflationSwap",'Maturity',Maturity,'FixedInflationRate',FixedInflationRate,'Notional',Notional,'Name',"YYInflationSwap_instrument")

%% Create Inflation Pricer Object
% Use finpricer to create an Inflation pricer object and use the ratecurve object with the 'DiscountCurve' name-value pair argument and the inflationcurve object with the 'InflationCurve' name-value pair argument.

outPricer = finpricer("Inflation",'DiscountCurve',ZeroCurve,'InflationCurve',myInflationCurve)

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

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

%% Compute Cash Flows for YearYearInflationSwap Instrument
% Use inflationCashflows to compute the cash flows for the YearYearInflationSwap instrument.

outCF = inflationCashflows(YYInflationSwap,datetime(2021,1,15),myInflationCurve)

% Copyright 2020 The MathWorks, Inc.