%% Price SOFR Future Using ratecurve and Discount Pricer
% This example shows the workflow to price an OISFuture instrument for a one-month SOFR future 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 instrument.

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;
 
myRC = ratecurve('zero',Settle,ZeroDates,ZeroRates)

%% Create OISFuture Instrument Object
% Use fininstrument to create an OISFuture instrument object for a one-month SOFR future.

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;
Maturity_1M = lbusdate(2021,3,[],[],'datetime');
StartDate_1M = fbusdate(2021,3,[],[],'datetime');
FutInstrument_1M = fininstrument("OISFuture","Maturity",Maturity_1M ,"QuotedPrice",Prices_1M,"StartDate",StartDate_1M,"Method","Average",...
    'HistoricalFixing',HistFixing,'Name',"1MonthSOFRFuture")

%% 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 for SOFR Future
% Use price to compute the price and sensitivities for the OISFuture instrument for a one-month SOFR future.

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

% Copyright 2021 The MathWorks, Inc.