%% Price Barrier Instrument Using Heston Model and Asset Monte-Carlo Pricer
% This example shows the workflow to price an Barrier instrument when you use a Heston model and an AssetMonteCarlo pricing method.
%% Create Barrier Instrument Object
% Use fininstrument to create an Barrier instrument object.

BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue',40,'Name',"barrier_option")

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

HestonModel = finmodel("Heston",'V0',0.032,'ThetaV',0.1,'Kappa',0.003,'SigmaV',0.2,'RhoSV',0.9)

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

Settle = datetime(2018,1,1);
Maturity = datetime(2023,1,1);
Rate = 0.035;
myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)

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

outPricer = finpricer("AssetMonteCarlo",'DiscountCurve',myRC,"Model",HestonModel,'SpotPrice',200,'simulationDates',datetime(2019,1,1))

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

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

% Copyright 2020 The MathWorks, Inc.