%% Use SABR-BraceGatarekMusiela Model (Rebonato Parameteric Form) and IRMonteCarlo Pricer to Price Float Bond Instrument
% This example shows the workflow to price a FloatBond instrument when you use a SABRBraceGatarekMusiela model in Rebonato parametric form and an IRMonteCarlo pricing method.
%% Create FloatBond Instrument Object
% Use fininstrument to create a FloatBond instrument object.

FloatB = fininstrument("FloatBond",'Maturity',datetime(2021,7,1),'Spread',0.025,'Reset',2,'Basis',1,'Principal',100,'EndMonthRule',false,'Name',"float_bond_instrument")

%
%% Create Rebonato Form SABRBraceGatarekMusiela Model Object
% Use finmodel to create a SABRBraceGatarekMusiela model object that is a SABR-BGM model in Rebonato parametric form.

Alpha = [0.4;0.34;0.31;0.28];
Beta = [0.5;0.5;0.5;0.5];
numRates = 5;

SABRBGMVolVolFunc = @(a,t) (a(1)*t + a(2)).*exp(-a(3)*t) + a(4);
SABRBGMVolVolParams = [.3 -.02 .7 .14];

SABRBGMVolFunc = @(a,t) (a(1)*t + a(2)).*exp(-a(3)*t) + a(4);
SABRBGMVolParams = [.2 -.01 .8 .16];
VolFunc(1:numRates-1,1) = {@(t) SABRBGMVolFunc(SABRBGMVolParams,t)};

VolVolFunc(1:numRates-1,1) = {@(t) SABRBGMVolVolFunc(SABRBGMVolVolParams,t)};

CorrFunc = @(i,j,B) exp(-B*abs(i-j));
FwdFwdCorrelation = CorrFunc(meshgrid(1:numRates-1)',meshgrid(1:numRates-1),.08);
VolVolCorrelation = CorrFunc(meshgrid(1:numRates-1)',meshgrid(1:numRates-1),.04);
SABRRho = [0.0005;0.0006;0.0060;0.0055];
FwdVolCorrelation = diag(SABRRho);

SABRBGM_Rebonato_param = finmodel("SABRBraceGatarekMusiela",'Alpha',Alpha,'Beta',Beta,'VolatilityofVolatility',VolVolFunc,'Volatility',VolFunc,'FwdFwdCorrelation',FwdFwdCorrelation,'VolVolCorrelation',VolVolCorrelation,'FwdVolCorrelation',FwdVolCorrelation)

%% Create ratecurve Object
% Create a ratecurve object using ratecurve.

Settle = datetime(2019,1,1);
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 IRMonteCarlo Pricer Object
% Use finpricer to create an IRMonteCarlo pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

simDates = datetime(2019,7,1)+calmonths(0:6:24);
outPricer = finpricer("IRMonteCarlo",'Model',SABRBGM_Rebonato_param,'DiscountCurve',myRC,'SimulationDates',simDates)

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

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

% You can access the simulated interest-rate Paths in the PricerData output.

outPR.PricerData

% Copyright 2021 The MathWorks, Inc.