%% Calculate Cash Flow for FRA Instrument
% This example shows the workflow to price a FRA (forward rate agreement) instrument and then use cashflows to determine the cash flow for the FRA instrument.
%% Create FRA Instrument Object
% Use fininstrument to create a FRA instrument object.

FRAObj = fininstrument("FRA",'StartDate',datetime(2020,9,15),'Maturity',datetime(2022,9,15),'Rate',0.175)

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

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

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

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

% Use cashflows for the FRA instrument with a Settle date of 15-Dec-2021. The specified Settle date must be before the instrument Maturity date.

CF = cashflows(FRAObj,datetime(2021,12,15))

% Copyright 2019 The MathWorks, Inc.