%% Price a Vanilla Instrument for Foreign Exchange Using Black-Scholes Model and Black-Scholes Pricer
% This example shows the workflow to price a Vanilla instrument for foreign exchange (FX) when you use a BlackScholes model and a BlackScholes 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 Vanilla Instrument Object
% Use fininstrument to create a Vanilla instrument object.

VanillaOpt = fininstrument("Vanilla",'ExerciseDate',datetime(2022,9,15),'Strike',.50,'OptionType',"put",'ExerciseStyle',"european",'Name',"vanilla_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 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 BlackScholes Pricer Object
% Use finpricer to create a BlackScholes pricer object and use the ratecurve object for the 'DiscountCurve' name-value pair argument. When pricing currencies using a Vanilla instrument, the DividendType must be 'continuous' and DividendValue is the annualized risk-free interest rate in the foreign country.

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

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

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

% Copyright 2019 The MathWorks, Inc.