%% Calculate Cash Flow for OIS Future Instrument
% This example shows the workflow to price an OISFuture instrument and then use cashflows to calculate the cashflow for the OISFuture instrument.
%% Create ratecurve Object
% Create a ratecurve object using ratecurve for the underlying interest-rate curve for the STIRFuture instrument.

Settle = datetime(2019,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 OISFuture Instrument Object
% Use fininstrument to create an OISFuture instrument object.

OISFuture = fininstrument("OISFuture",'Maturity',datetime(2022,12,15),'QuotedPrice',99.5,'StartDate',datetime(2022,9,15),'Notional',90,'ProjectionCurve',myRC,'Name',"ois_future_instrument")

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

outPricer = finpricer("Discount",'DiscountCurve',myRC)

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

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

% Use cashflows to calculate the cash flow for the OISFuture instrument with a Settle date of 15-Sep-2022. The specified Settle date must be before the instrument Maturity date.

CF = cashflows(OISFuture,datetime(2022,9,15))

% Copyright 2021 The MathWorks, Inc.