barriersensbyfd
Calculate barrier option prices or sensitivities using finite difference method
Syntax
Description
[
calculates European and American barrier option prices or sensitivities of a single
underlying asset using the finite difference method. PriceSens
,PriceGrid
,AssetPrices
,Times
]
= barriersensbyfd(RateSpec
,StockSpec
,OptSpec
,Strike
,Settle
,ExerciseDates
,BarrierSpec
,Barrier
)barrierbyfd
assumes that the barrier is continuously monitored.
Note
Alternatively, you can use the Barrier
object to calculate price or sensitivities for Barrier options. For more
information, see Get Started with Workflows Using ObjectBased Framework for Pricing Financial Instruments.
[
adds optional namevalue pair arguments. PriceSens
,PriceGrid
,AssetPrices
,Times
]
= barriersensbyfd(___,Name,Value
)barriersesbyfd
assumes
that the barrier is continuously monitored.
Examples
Calculate Price and Sensitivities for a Barrier Down and Out Call Option Using Finite Difference Method
Create a RateSpec
.
AssetPrice = 50; Strike = 45; Rate = 0.035; Volatility = 0.30; Settle = datetime(2015,1,1); Maturity = datetime(2016,1,1); Basis = 1; RateSpec = intenvset('ValuationDate',Settle,'StartDates',Settle,'EndDates',... Maturity,'Rates',Rate,'Compounding',1,'Basis',Basis)
RateSpec = struct with fields:
FinObj: 'RateSpec'
Compounding: 1
Disc: 0.9656
Rates: 0.0350
EndTimes: 1
StartTimes: 0
EndDates: 736330
StartDates: 735965
ValuationDate: 735965
Basis: 1
EndMonthRule: 1
Create a StockSpec
.
StockSpec = stockspec(Volatility,AssetPrice)
StockSpec = struct with fields:
FinObj: 'StockSpec'
Sigma: 0.3000
AssetPrice: 50
DividendType: []
DividendAmounts: 0
ExDividendDates: []
Calculate the Price
, Delta
, and Theta
of a European Down and Out call option using the finite difference method.
Barrier = 40; BarrierSpec = 'DO'; OptSpec = 'Call'; OutSpec = {'price';'delta';'theta'}; [Price, Delta, Theta] = barriersensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,... Maturity, BarrierSpec,Barrier,'Outspec',OutSpec)
Price = 8.5020
Delta = 0.8569
Theta = 1.8502
Input Arguments
StockSpec
— Stock specification for underlying asset
structure
Stock specification for the underlying asset. For information
on the stock specification, see stockspec
.
stockspec
handles several
types of underlying assets. For example, for physical commodities
the price is StockSpec.Asset
, the volatility is StockSpec.Sigma
,
and the convenience yield is StockSpec.DividendAmounts
.
Data Types: struct
OptSpec
— Definition of option
character vector with values 'call'
or
'put'
 string array with values 'call'
or
'put'
Definition of an option as 'call'
or 'put'
, specified as
a character vector or string array with values "call"
or
"put"
.
Data Types: char
 string
Strike
— Option strike price value
numeric
Option strike price value, specified as a scalar numeric.
Data Types: double
Settle
— Settlement or trade date
datetime scalar  string scalar  date character vector
Settlement or trade date for the barrier option, specified as a scalar datetime, string, or date character vector.
To support existing code, barriersensbyfd
also
accepts serial date numbers as inputs, but they are not recommended.
ExerciseDates
— Option exercise dates
datetime array  string array  date character vector
Option exercise dates, specified as a datetime array, string array, or date character vectors:
For a European option, there is only one
ExerciseDates
on the option expiry date which is the maturity of the instrument.For an American option, use a
1
by2
vector of exercise date boundaries. The option can be exercised on any date between or including the pair of dates on that row. If only one nonNaN
date is listed, the option can be exercised betweenSettle
and the single listed date inExerciseDates
.
To support existing code, barriersensbyfd
also
accepts serial date numbers as inputs, but they are not recommended.
BarrierSpec
— Barrier option type
character vector with values: 'UI'
, 'UO'
, 'DI'
, 'DO'
Barrier option type, specified as a character vector with the following values:
'UI'
— Up KnockinThis option becomes effective when the price of the underlying asset passes above the barrier level. It gives the option holder the right, but not the obligation, to buy or sell (call/put) the underlying security at the strike price if the underlying asset goes above the barrier level during the life of the option. Note,
barrierbyfd
does not support American knockin barrier options.'UO'
— Up KnockoutThis option gives the option holder the right, but not the obligation, to buy or sell (call/put) the underlying security at the strike price as long as the underlying asset does not go above the barrier level during the life of the option. This option terminates when the price of the underlying asset passes above the barrier level. Usually, with an upandout option, the rebate is paid if the spot price of the underlying reaches or exceeds the barrier level.
'DI'
— Down KnockinThis option becomes effective when the price of the underlying stock passes below the barrier level. It gives the option holder the right, but not the obligation, to buy or sell (call/put) the underlying security at the strike price if the underlying security goes below the barrier level during the life of the option. With a downandin option, the rebate is paid if the spot price of the underlying does not reach the barrier level during the life of the option. Note,
barrierbyfd
does not support American knockin barrier options.'DO'
— Down KnockupThis option gives the option holder the right, but not the obligation, to buy or sell (call/put) the underlying asset at the strike price, as long as the underlying asset does not go below the barrier level during the life of the option. This option terminates when the price of the underlying security passes below the barrier level. Usually the option holder receives a rebate amount if the option expires worthless.
Option  Barrier Type  Payoff if Barrier Crossed  Payoff if Barrier not Crossed 

Call/Put  Down Knockout  Worthless  Standard Call/Put 
Call/Put  Down Knockin  Call/Put  Worthless 
Call/Put  Up Knockout  Worthless  Standard Call/Put 
Call/Put  Up Knockin  Standard Call/Put  Worthless 
Data Types: char
Barrier
— Barrier level
numeric
Barrier level, specified as a scalar numeric.
Data Types: double
NameValue Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Namevalue arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: PriceSens = barriersensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,Maturity,BarrierSpec,Barrier,Rebate,1000,AmericanOpt,1)
Rebate
— Rebate value
0
(default)  numeric
Rebate value, specified as the commaseparated pair consisting of 'Rebate'
and a scalar numeric. For Knockin options, the
Rebate
is paid at expiry. For
Knockout
options, the Rebate
is paid when the Barrier
is reached.
Data Types: double
OutSpec
— Define outputs
{'Price'}
(default)  character vector with values 'Price'
, 'Delta'
, 'Gamma'
, 'Vega'
, 'Lambda'
, 'Rho'
, 'Theta'
,
and 'All'
 cell array of character vectors with values 'Price'
, 'Delta'
, 'Gamma'
, 'Vega'
, 'Lambda'
, 'Rho'
, 'Theta'
,
and 'All'
Define outputs, specified as the commaseparated pair consisting of
'OutSpec'
and a NOUT

by1
or a
1
byNOUT
cell array of
character vectors with possible values of 'Price'
,
'Delta'
, 'Gamma'
,
'Vega'
, 'Lambda'
,
'Rho'
, 'Theta'
, and
'All'
.
OutSpec = {'All'}
specifies that the output
is Delta
, Gamma
, Vega
, Lambda
, Rho
, Theta
,
and Price
, in that order. This is the same as specifying OutSpec
to
include each sensitivity.
Example: OutSpec = {'delta','gamma','vega','lambda','rho','theta','price'}
Data Types: char
 cell
AssetGridSize
— Size of asset grid used for finite difference grid
400
(default)  positive numeric
Size of the asset grid used for a finite difference grid, specified as the commaseparated
pair consisting of 'AssetGridSize'
and a scalar
positive numeric.
Data Types: double
TimeGridSize
— Size of time grid used for finite difference grid
100
(default)  positive numeric
Size of the time grid used for a finite difference grid, specified as the commaseparated pair
consisting of 'TimeGridSize'
and a scalar positive
numeric.
Data Types: double
AmericanOpt
— Option type
0
European (default)  integer with values 0
or
1
Option type, specified as the commaseparated pair consisting of
'AmericanOpt'
and a scalar flag with one of the
following values:
0
— European1
— American
Data Types: logical
Output Arguments
PriceSens
— Expected prices or sensitivities values for barrier options
matrix
Expected prices or sensitivities (defined using OutSpec
)
for barrier options, returned as a NINST
by1
matrix.
PriceGrid
— Grid containing prices calculated by finite difference method
grid
Grid containing prices calculated by the finite difference method,
returned as a twodimensional grid with size PriceGridSize*length(Times)
.
The number of columns does not have to be equal to the TimeGridSize
,
because exdividend dates in the StockSpec
are
added to the time grid. The price for t = 0
is
contained in PriceGrid(:, end)
.
Times
— Times corresponding to second dimension of PriceGrid
vector
Times corresponding to the second dimension of the PriceGrid
,
returned as a vector.
More About
Barrier Option
A Barrier option has not only a strike price but also a barrier level and sometimes a rebate.
A rebate is a fixed amount that is paid if the option cannot be exercised because the barrier
level has been reached or not reached. The payoff for this type of option depends on
whether the underlying asset crosses the predetermined trigger value (barrier
level), indicated by Barrier
, during the life of the option.
For more information, see Barrier Option.
References
[1] Hull, J. Options, Futures and Other Derivatives. Fourth Edition. Prentice Hall, 2000, pp. 646–649.
[2] Aitsahlia, F., L. Imhof, and T.L. Lai. “Pricing and hedging of American knockin options.” The Journal of Derivatives. Vol. 11.3 , 2004, pp. 44–50.
[3] Rubinstein M. and E. Reiner. “Breaking down the barriers.” Risk. Vol. 4(8), 1991, pp. 28–35.
Version History
Introduced in R2016bR2022b: Serial date numbers not recommended
Although barriersensbyfd
supports serial date numbers,
datetime
values are recommended instead. The
datetime
data type provides flexible date and time
formats, storage out to nanosecond precision, and properties to account for time
zones and daylight saving time.
To convert serial date numbers or text to datetime
values, use the datetime
function. For example:
t = datetime(738427.656845093,"ConvertFrom","datenum"); y = year(t)
y = 2021
There are no plans to remove support for serial date number inputs.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)