%% Use Levy Pricer and Black-Scholes Model to Price Asian Instrument for Foreign Exchange
% This example shows the workflow to price an Asian instrument for an arithmetic average currency option when you use a BlackScholes model and a Levy pricing method. Assume that the current exchange rate is $0.52 and has a volatility of 12% per annum. The annualized continuously compounded foreign risk-free rate is 8% per annum.
%% Create Asian Instrument Object
% Use fininstrument to create an Asian instrument object.

AsianOpt = fininstrument("Asian",'ExerciseDate',datetime(2022,9,15),'Strike',.50,'OptionType',"put",'ExerciseStyle',"european",'Name',"asian_fx_option")

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

Sigma = .12;
BlackScholesModel = finmodel("BlackScholes",'Volatility',Sigma)

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

Settle = datetime(2018,9,15);
Type = 'zero';
ZeroTimes = [calmonths(6) calyears([1 2 3 4 5 7 10 20 30])]';
ZeroRates = [0.0052 0.0055 0.0061 0.0073 0.0094 0.0119 0.0168 0.0222 0.0293 0.0307]';
ZeroDates = Settle + ZeroTimes;
 
myRC = ratecurve('zero',Settle,ZeroDates,ZeroRates)

%% Create Levy Pricer Object
% Use finpricer to create a Levy pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument. When you price currencies using a Asian instrument for an arithmetic average currency option, DividendType must be "continuous" and DividendValue is the annualized risk-free interest rate in the foreign country.

ForeignRate = 0.08;
outPricer = finpricer("analytic",'Model',BlackScholesModel,'DiscountCurve',myRC,'SpotPrice',.52,'DividendType',"continuous",'DividendValue',ForeignRate,'PricingMethod',"Levy")

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

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

% Copyright 2019 The MathWorks, Inc.