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

BinaryOpt = fininstrument("Binary",'ExerciseDate',datetime(2022,9,15),'Strike',100,'PayoffValue',130,'OptionType',"put",'Name',"binary_option")

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

MertonModel = finmodel("Merton",'Volatility',0.25,'MeanJ',0.02,'JumpVol',0.07,'JumpFreq',0.09)

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

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

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

outPricer = finpricer("AssetMonteCarlo",'DiscountCurve',myRC,"Model",MertonModel,'SpotPrice',102,'simulationDates',datetime(2022,9,15))

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

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

% Copyright 2020 The MathWorks, Inc.