%% Price Variance Swap Instrument Using Heston Model and Heston Pricer
% This example shows the workflow to price a VarianceSwap instrument when you use a Heston model and a Heston pricing method.
%% Create VarianceSwap Instrument Object
% Use fininstrument to create a VarianceSwap instrument object.

VarianceSwapInst = fininstrument("VarianceSwap",'Maturity',datetime(2020,9,15),'Notional',100,'StartDate',datetime(2020,6,15),'RealizedVariance',0.02,'Strike',0.05,'Name',"variance_swap_instrument")

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

HestonModel = finmodel("Heston",'V0',0.06,'ThetaV',0.1,'Kappa',0.9,'SigmaV',0.7,'RhoSV',-.3)

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

Settle = datetime(2020, 1, 1);
ZeroTimes = calmonths(3);
ZeroRates = 0.05;
ZeroDates = Settle + ZeroTimes;
Basis = 1;
ZeroCurve = ratecurve("zero",Settle,ZeroDates,ZeroRates,'Basis',Basis)

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

outPricer = finpricer("Analytic",'DiscountCurve',ZeroCurve,'Model',HestonModel)

%% Price VarianceSwap Instrument
% Use price to compute the price and fair variance for the VarianceSwap instrument.

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

% Copyright 2020 The MathWorks, Inc.