%% Use SABR Model and SABR Pricer to Price Swaption Instrument
% This example shows the workflow to price a Swaption instrument when you use a SABR model and a SABR pricing method.
%% 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 Swap Instrument Object
% Use fininstrument to create the underlying Swap instrument object.

Swap = fininstrument("Swap",'Maturity',datetime(2023,1,30),'LegRate',[0.018 0.24],'LegType',["fixed","float"],'Basis',5,'Notional',1000,'StartDate',datetime(2020,3,30),'DaycountAdjustedCashFlow',true,'BusinessDayConvention',"follow",'ProjectionCurve',myRC,'Name',"swap_instrument")

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

Swaption = fininstrument("swaption",'Strike',0.25,'ExerciseDate',datetime(2021,7,30),'Swap',Swap,'OptionType',"put",'ExerciseStyle',"european",'Name',"swaption_instrument")

%
%% Create SABR Model Object
% Use finmodel to create a SABR model object.

SabrModel = finmodel("SABR",'Alpha',0.032,'Beta',0.04, 'Rho', .08, 'Nu', 0.49,'Shift',0.002)

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

outPricer = finpricer("analytic",'Model',SabrModel,'DiscountCurve',myRC)

%% Price Swaption Instrument
% Use price to compute the price for the Swaption instrument.

Price = price(outPricer,Swaption)

% Copyright 2019 The MathWorks, Inc.