%% Price Double Barrier Instrument Using Black-Scholes Model and Finite Difference Pricer
% This example shows the workflow to price an DoubleBarrier instrument when you use a BlackScholes model and a FiniteDifference pricing method.
%% Create DoubleBarrier Instrument Object
% Use fininstrument to create a DoubleBarrier instrument object.

DoubleBarrierOpt = fininstrument("DoubleBarrier",'Strike',75,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DKO",'BarrierValue',[110 80],'Name',"doublebarrier_option")

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

BlackScholesModel = finmodel("BlackScholes",'Volatility',0.30)

%% 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 FiniteDifference Pricer Object
% Use finpricer to create a FiniteDifference pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

outPricer = finpricer("FiniteDifference",'Model',BlackScholesModel,'DiscountCurve',myRC,'SpotPrice',100)

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

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

% Copyright 2019 The MathWorks, Inc.