%% Use Merton Model and Numerical Integration Pricer to Price Vanilla Instrument
% This example shows the workflow to price a Vanilla instrument when you use a Merton model and a NumericalIntegration pricing method.
%% Create Vanilla Instrument Object
% Use fininstrument to create a Vanilla instrument object.

VanillaOpt = fininstrument("Vanilla",'ExerciseDate',datetime(2022,9,15),'Strike',105,'OptionType',"put",'ExerciseStyle',"european",'Name',"vanilla_option")

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

MertonModel = finmodel("Merton",'Volatility',0.45,'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 NumericalIntegration Pricer Object
% Use finpricer to create a NumericalIntegration pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument.

outPricer = finpricer("numericalintegration",'DiscountCurve',myRC,'Model',MertonModel,'SpotPrice',100,'DividendValue',0.45,'VolRiskPremium',0.09,'LittleTrap',false,'AbsTol',0.5,'RelTol',0.04,'Framework','lewis2001')

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

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

%
% Copyright 2019 The MathWorks, Inc.