%% Price Multiple SOFR Futures Using ratecurve and Discount Pricer
% This example shows the workflow to price multiple OISFuture instruments for one-month SOFR futures and three-month SOFR futures when you use a ratecurve object and a Discount pricing method.
%% Create ratecurve Object
% Create a ratecurve object using ratecurve for the underlying interest-rate curve for the OISFuture instruments.

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 Objects for SOFR Futures
% Use fininstrument to create an OISFuture instrument object for one-month SOFR futures.

HFDates = datetime(2021,3,1) + caldays(0:3)';
HistFixing = timetable(HFDates,[0.02;0.04;0.04;0.02]);

% Data from the following: https://www.cmegroup.com/trading/interest-rates/stir/one-month-sofr_quotes_globex.html
Prices_1M = [99.97 99.96 99.95]';
Maturity_1M = lbusdate(2021,[3 4 5]',[],[],'datetime');
StartDate_1M = fbusdate(2021,[3 4 5]',[],[],'datetime');
FutInstruments_1M = fininstrument("OISFuture","Maturity",Maturity_1M ,"QuotedPrice",Prices_1M,"StartDate",StartDate_1M,"Method","Average",...
    'HistoricalFixing',HistFixing,'Name',"1MonthSOFRFuture")

% Use fininstrument to create an OISFuture instrument object for three-month SOFR futures.

% Data from the following: https://www.cmegroup.com/trading/interest-rates/stir/three-month-sofr_quotes_globex.html
Prices_3M = [99.92 99.895 99.84 99.74]';
Dates_3M_Maturity = thirdwednesday([6 9 12 3]',[2021 2021 2021 2022]','datetime');
Dates_3M_Start = thirdwednesday([3 6 9 12]',2021,'datetime');
FutInstruments_3M = fininstrument("OISFuture","Maturity",Dates_3M_Maturity,...
    "QuotedPrice",Prices_3M,"StartDate",Dates_3M_Start,'HistoricalFixing',HistFixing,'Name',"3MonthSOFRFuture")

%% 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 Instruments for SOFR Futures
% Use price to compute the prices for the OISFuture instruments for one-month and three-month SOFR futures.

Price = price(outPricer,[FutInstruments_1M ; FutInstruments_3M])

% Copyright 2021 The MathWorks, Inc.