Barrier
Description
Create and price a Barrier
instrument object for one or
more Barrier instruments using this workflow:
Use
fininstrument
to create aBarrier
instrument object for one or more Barrier instruments.Use
finmodel
to specify aBlackScholes
,Heston
,Bates
, orMerton
model for theBarrier
instrument object.Choose a pricing method.
When using a
BlackScholes
model, usefinpricer
to specify aBlackScholes
,AssetTree
, orVannaVolga
pricing method for one or moreBarrier
instruments.When using a
BlackScholes
,Heston
,Bates
, orMerton
model, usefinpricer
to specify anAssetMonteCarlo
orFiniteDifference
pricing method for one ore moreBarrier
instruments.
For more information on this workflow, see Get Started with Workflows Using Object-Based Framework for Pricing Financial Instruments.
For more information on the available models and pricing methods for a
Barrier
instrument, see Choose Instruments, Models, and Pricers.
Creation
Syntax
Description
creates a BarrierOpt
= fininstrument(InstrumentType
,'Strike
',strike_value,'ExerciseDate
',exercise_date,'BarrierValue
',barrier_value)Barrier
instrument object for one or more
Barrier instruments by specifying InstrumentType
and
sets the properties for the
required name-value pair arguments Strike
,
ExerciseDate
, and
BarrierValue
.
sets optional properties using
additional name-value pairs in addition to the required arguments in the
previous syntax. For example, BarrierOpt
= fininstrument(___,Name,Value
)BarrierOpt =
fininstrument("Barrier",'Strike',100,'ExerciseDate',datetime(2019,1,30),'BarrierValue',110,'OptionType',"put",'ExerciseStyle',"European",'BarrierType',"DO",'Name',"barrier_option")
creates a Barrier
put option with an European exercise.
You can specify multiple name-value pair arguments.
Input Arguments
InstrumentType
— Instrument type
string with value "Barrier"
| string with value "Barrier"
| string array with values of "Barrier"
| character vector with value 'Barrier'
| cell array of character vectors with values of
'Barrier'
Instrument type, specified as a string with the value of
"Barrier"
, a character vector with the value of
'Barrier'
, an
NINST
-by-1
string array with
values "Barrier"
, or an
NINST
-by-1
cell array of
character vectors with values of 'Barrier'
.
Data Types: char
| string
| cell
Specify required
and optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where
Name
is the argument name and Value
is
the corresponding value. Name-value 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: BarrierOpt =
fininstrument("Barrier",'Strike',100,'ExerciseDate',datetime(2019,1,30),'BarrierValue',110,'OptionType',"put",'ExerciseStyle',"European",'BarrierType',"DO",'Name',"barrier_option")
Barrier
Name-Value Pair ArgumentsStrike
— Option strike value
nonnegative value | vector of nonnegative values
Option strike value, specified as the comma-separated pair
consisting of 'Strike'
and a scalar nonnegative
value or an NINST
-by-1
vector
of nonnegative values.
Data Types: double
ExerciseDate
— Option exercise date
datetime array | string array | date character vector
Option exercise date, specified as the comma-separated pair
consisting of 'ExerciseDate'
and a scalar or an
NINST
-by-1
vector using a
datetime array, string array, or date character vectors.
Note
For a European option, there is only one
ExerciseDate
on the option expiry
date.
To support existing code, Barrier
also
accepts serial date numbers as inputs, but they are not recommended.
If you use date character vectors or strings, the format must be
recognizable by datetime
because
the ExerciseDate
property is stored as a
datetime.
BarrierValue
— Barrier level
scalar numeric | numeric vector
Barrier level, specified as the comma-separated pair consisting of
'BarrierLevel'
and a scalar numeric or an
NINST
-by-1
numeric
vector.
Data Types: double
Barrier
Name-Value Pair ArgumentsOptionType
— Option type
"call"
(default) | string with value "call"
or "put"
| string array with values "call"
or "put"
| character vector with value 'call'
or
'put'
| cell array of character vectors with values
'call'
or 'put'
Option type, specified as the comma-separated pair consisting of
'OptionType'
and a scalar character vector or
string or an NINST
-by-1
cell
array of character vectors or string array.
A barrier call option gives the holder the right, but not the obligation, to buy the underlying asset at a predetermined strike price if the barrier condition is met. A barrier put option gives the holder the right, but not the obligation, to sell the underlying asset at a predetermined strike price if the barrier condition is met.
Data Types: char
| cell
| string
ExerciseStyle
— Option exercise style
"European"
(default) | string with value "European"
or "American"
| string array with values "European"
or
"American"
| character vector with value 'European'
or
'American'
| cell array of character vectors with values
'European'
or
'American'
Option exercise style, specified as the comma-separated pair
consisting of 'ExerciseStyle'
and a scalar string
or character vector or an
NINST
-by-1
cell array of
character vectors or string array.
Note
For a Barrier
option, the BlackScholes
pricer supports only
"European"
exercise and the FiniteDifference
pricer supports an
"American"
or
"European"
exercise.
Data Types: string
| char
| cell
BarrierType
— Barrier option type
"UO"
(default) | string with value "UI"
, "UO"
, "DI"
, or "DO"
| string array with values "UI"
,
"UO"
, "DI"
, or
"DO"
| character vector with value 'UI'
,
'UO'
, 'DI'
, or
'DO'
| cell array of character vectors with values
'UI'
, 'UO'
,
'DI'
, or 'DO'
Barrier option type, specified as the comma-separated pair
consisting of 'BarrierType'
and a scalar string
or character vector or an
NINST
-by-1
cell array of
character vectors or string array with one of the following values:
"UI"
— Up knock-inThis option becomes effective when the price of the underlying asset passes above the barrier level. If the underlying asset goes above the barrier level during the life of the option, the option holder has the right, but not the obligation, to buy or sell (call or put) the underlying security at the strike price.
"UO"
— Up knock-outThis option gives the option holder the right, but not the obligation, to buy or sell (call or 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 security passes above the barrier level. If the spot price of the underlying asset reaches or exceeds the barrier level with an up-and-out option, the rebate is paid.
"DI"
— Down knock-inThis option becomes effective when the price of the underlying stock passes below the barrier level. If the underlying security goes below the barrier level during the life of the option, the option holder has the right, but not the obligation, to buy or sell (call or put) the underlying security at the strike price. With a down-and-in 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 that a
Barrier
instrument using theFiniteDifference
pricer does not support American knock-in barrier options."DO"
— Down knock-upThis option gives the option holder the right, but not the obligation, to buy or sell (call or 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. If the option is worthless when it expires, the option holder receives a rebate amount.
Option | Barrier Type | Payoff If Barrier Crossed | Payoff If Barrier Not Crossed |
---|---|---|---|
Call or Put | Down knock-out | Worthless | Standard Call or Put |
Call or Put | Down knock-in | Call or Put | Worthless |
Call or Put | Up knock-out | Worthless | Standard Call or Put |
Call or Put | Up knock-in | Standard Call or Put | Worthless |
Data Types: char
| cell
| string
Rebate
— Rebate value
0
(default) | scalar numeric | numeric vector
Rebate value, specified as the comma-separated pair consisting of
'Rebate'
and a scalar numeric or an
NINST
-by-1
numeric vector.
For knock-in options, the
Rebate
is paid at expiry.For knock-out options, the
Rebate
is paid whenBarrierValue
is reached.
Data Types: double
Name
— User-defined name for instrument
" "
(default) | string | string array | character vector | cell array of character vectors
User-defined name for the instrument, specified as the
comma-separated pair consisting of 'Name'
and a
scalar string or character vector or an
NINST
-by-1
cell array of
character vectors or string array.
Data Types: char
| cell
| string
Properties
Strike
— Option strike value
nonnegative value | vector of nonnegative values
Option strike value, returned as a scalar nonnegative value or an
NINST
-by-1
vector of nonnegative
values.
Data Types: double
ExerciseDate
— Option exercise date
datetime | vector of datetimes
Option exercise date, returned as a datetime or an
NINST
-by-1
vector of
datetimes.
Data Types: datetime
OptionType
— Option type
"call"
(default) | string with value "call"
or "put"
| string array with values "call"
or "put"
Option type, returned as a scalar string or an
NINST
-by-1
string array with the
values of "call"
or "put"
.
Data Types: string
ExerciseStyle
— Option exercise style
"European"
(default) | string with value "European"
or "American"
| string array with values "European"
or "American"
Option exercise style, returned as a scalar string or
NINST
-by-1
string array with the
values of "European"
or "American"
.
Data Types: string
BarrierSpec
— Barrier option type
"UO"
European (default) | string with value "UI"
, "UO"
, "DI"
, or "DO"
| string array with values "UI"
, "UO"
, "DI"
, or
"DO"
Barrier option type, returned as a scalar string or
NINST
-by-1
string array with the
values of "UI"
, "UO"
,
"DI"
, or "DO"
.
Data Types: string
BarrierValue
— Barrier level
scalar numeric | numeric vector
Barrier level, returned as a scalar numeric or an
NINST
-by-1
numeric vector.
Data Types: double
Rebate
— Rebate value
0
(default) | scalar numeric | numeric vector
Rebate value, returned as a scalar numeric or an
NINST
-by-1
numeric vector.
Data Types: double
Name
— User-defined name for instrument
" "
(default) | string | string array
User-defined name for the instrument, returned as a string or an
NINST
-by-1
string array.
Data Types: string
Examples
Price Barrier
Instrument Using BlackScholes
Model and FiniteDifference
Pricer
This example shows the workflow to price an Barrier
instrument when you use a BlackScholes
model and a FiniteDifference
pricing method.
Create Barrier
Instrument Object
Use fininstrument
to create an Barrier
instrument object.
BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue',40,'Name',"barrier_option")
BarrierOpt = Barrier with properties: OptionType: "call" Strike: 45 BarrierType: "do" BarrierValue: 40 Rebate: 0 ExerciseStyle: "american" ExerciseDate: 01-Jan-2019 Name: "barrier_option"
Create BlackScholes
Model Object
Use finmodel
to create a BlackScholes
model object.
BlackScholesModel = finmodel("BlackScholes",'Volatility',0.30)
BlackScholesModel = BlackScholes with properties: Volatility: 0.3000 Correlation: 1
Create ratecurve
Object
Create a flat ratecurve
object using ratecurve
.
Settle = datetime(2018,1,1); Maturity = datetime(2023,1,1); Rate = 0.035; myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)
myRC = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 1 Dates: 01-Jan-2023 Rates: 0.0350 Settle: 01-Jan-2018 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous"
Create FiniteDifference
Pricer Object
Use finpricer
to create a FiniteDifference
pricer object and use the ratecurve
object for the 'DiscountCurve'
name-value pair argument.
outPricer = finpricer("FiniteDifference",'Model',BlackScholesModel,'DiscountCurve',myRC,'SpotPrice',50)
outPricer = FiniteDifference with properties: DiscountCurve: [1x1 ratecurve] Model: [1x1 finmodel.BlackScholes] SpotPrice: 50 GridProperties: [1x1 struct] DividendType: "continuous" DividendValue: 0
Price Barrier
Instrument
Use price
to compute the price and sensitivities for the Barrier
instrument.
[Price, outPR] = price(outPricer,BarrierOpt,["all"])
Price = 8.5014
outPR = priceresult with properties: Results: [1x7 table] PricerData: [1x1 struct]
outPR.Results
ans=1×7 table
Price Delta Gamma Lambda Theta Rho Vega
______ _______ _________ ______ _______ ______ ______
8.5014 0.85673 0.0057199 5.0388 -1.8461 26.238 6.1837
Price Multiple Barrier
Instruments Using BlackScholes
Model and FiniteDifference
Pricer
This example shows the workflow to price multiple Barrier
instruments when you use a BlackScholes
model and a FiniteDifference
pricing method.
Create Barrier
Instrument Object
Use fininstrument
to create an Barrier
instrument object for three Barrier instruments.
BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime([2019,1,1; 2019,2,1 ; 2019,3,1]),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue', [40; 30; 20],'Name',"barrier_option")
BarrierOpt=3×1 Barrier array with properties:
OptionType
Strike
BarrierType
BarrierValue
Rebate
ExerciseStyle
ExerciseDate
Name
Create BlackScholes
Model Object
Use finmodel
to create a BlackScholes
model object.
BlackScholesModel = finmodel("BlackScholes",'Volatility',0.30)
BlackScholesModel = BlackScholes with properties: Volatility: 0.3000 Correlation: 1
Create ratecurve
Object
Create a flat ratecurve
object using ratecurve
.
Settle = datetime(2018,1,1); Maturity = datetime(2023,1,1); Rate = 0.035; myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)
myRC = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 1 Dates: 01-Jan-2023 Rates: 0.0350 Settle: 01-Jan-2018 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous"
Create FiniteDifference
Pricer Object
Use finpricer
to create a FiniteDifference
pricer object and use the ratecurve
object for the 'DiscountCurve'
name-value pair argument.
outPricer = finpricer("FiniteDifference",'Model',BlackScholesModel,'DiscountCurve',myRC,'SpotPrice',50)
outPricer = FiniteDifference with properties: DiscountCurve: [1x1 ratecurve] Model: [1x1 finmodel.BlackScholes] SpotPrice: 50 GridProperties: [1x1 struct] DividendType: "continuous" DividendValue: 0
Price Barrier
Instruments
Use price
to compute the prices and sensitivities for the Barrier
instruments.
[Price, outPR] = price(outPricer,BarrierOpt,["all"])
Price = 3×1
8.5014
9.7112
9.9901
outPR=3×1 priceresult array with properties:
Results
PricerData
outPR.Results
ans=1×7 table
Price Delta Gamma Lambda Theta Rho Vega
______ _______ _________ ______ _______ ______ ______
8.5014 0.85673 0.0057199 5.0388 -1.8461 26.238 6.1837
ans=1×7 table
Price Delta Gamma Lambda Theta Rho Vega
______ _______ ________ ______ _______ ______ ______
9.7112 0.73186 0.020793 3.7681 -3.2754 29.014 16.885
ans=1×7 table
Price Delta Gamma Lambda Theta Rho Vega
______ ______ ________ ______ _______ ______ ______
9.9901 0.7296 0.020326 3.6516 -3.2151 30.872 17.803
Price Barrier
Instrument Using BlackScholes
Model and AssetTree
Pricer for EQP Binomial Tree
This example shows the workflow to price an Barrier
instrument when you use a BlackScholes
model and an AssetTree
pricing method using an Equal Probability (EQP) tree.
Create Barrier
Instrument Object
Use fininstrument
to create an Barrier
instrument object.
BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue',40,'Name',"barrier_option")
BarrierOpt = Barrier with properties: OptionType: "call" Strike: 45 BarrierType: "do" BarrierValue: 40 Rebate: 0 ExerciseStyle: "american" ExerciseDate: 01-Jan-2019 Name: "barrier_option"
Create BlackScholes
Model Object
Use finmodel
to create a BlackScholes
model object.
BlackScholesModel = finmodel("BlackScholes",'Volatility',0.30)
BlackScholesModel = BlackScholes with properties: Volatility: 0.3000 Correlation: 1
Create ratecurve
Object
Create a flat ratecurve
object using ratecurve
.
Settle = datetime(2018,1,1); Maturity = datetime(2023,1,1); Rate = 0.035; myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)
myRC = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 1 Dates: 01-Jan-2023 Rates: 0.0350 Settle: 01-Jan-2018 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous"
Create AssetTree
Pricer Object
Use finpricer
to create an AssetTree
pricer object with an EQP equity tree and use the ratecurve
object for the 'DiscountCurve'
name-value pair argument.
NumPeriods = 15; EQPPricer = finpricer("AssetTree",'DiscountCurve',myRC,'Model',BlackScholesModel,'SpotPrice',1000,'PricingMethod',"EqualProbability",'Maturity',datetime(2019,1,1),'NumPeriods',NumPeriods)
EQPPricer = EQPTree with properties: Tree: [1x1 struct] NumPeriods: 15 Model: [1x1 finmodel.BlackScholes] DiscountCurve: [1x1 ratecurve] SpotPrice: 1000 DividendType: "continuous" DividendValue: 0 TreeDates: [25-Jan-2018 08:00:00 18-Feb-2018 16:00:00 15-Mar-2018 00:00:00 08-Apr-2018 08:00:00 02-May-2018 16:00:00 27-May-2018 00:00:00 20-Jun-2018 08:00:00 14-Jul-2018 16:00:00 ... ] (1x15 datetime)
EQPPricer.Tree
ans = struct with fields:
Probs: [2x15 double]
ATree: {1x16 cell}
dObs: [01-Jan-2018 00:00:00 25-Jan-2018 08:00:00 18-Feb-2018 16:00:00 15-Mar-2018 00:00:00 08-Apr-2018 08:00:00 02-May-2018 16:00:00 27-May-2018 00:00:00 20-Jun-2018 08:00:00 14-Jul-2018 16:00:00 ... ] (1x16 datetime)
tObs: [0 0.0667 0.1333 0.2000 0.2667 0.3333 0.4000 0.4667 0.5333 0.6000 0.6667 0.7333 0.8000 0.8667 0.9333 1]
Price Barrier
Instrument
Use price
to compute the price and sensitivities for the Barrier
instrument.
[Price, outPR] = price(EQPPricer,BarrierOpt,["all"])
Price = 956.5478
outPR = priceresult with properties: Results: [1x7 table] PricerData: [1x1 struct]
outPR.Results
ans=1×7 table
Price Delta Gamma Vega Lambda Rho Theta
______ _____ __________ ___________ ______ _____ _______
956.55 1 9.3133e-18 -6.8212e-09 1.0454 43.45 -1.5208
outPR.PricerData.PriceTree
ans = struct with fields:
PTree: {1x16 cell}
ExTree: {1x16 cell}
tObs: [0 0.0667 0.1333 0.2000 0.2667 0.3333 0.4000 0.4667 0.5333 0.6000 0.6667 0.7333 0.8000 0.8667 0.9333 1]
dObs: [01-Jan-2018 25-Jan-2018 18-Feb-2018 15-Mar-2018 08-Apr-2018 02-May-2018 27-May-2018 20-Jun-2018 14-Jul-2018 08-Aug-2018 01-Sep-2018 25-Sep-2018 20-Oct-2018 13-Nov-2018 07-Dec-2018 01-Jan-2019]
Probs: [2x15 double]
Price Barrier
Instrument Using BlackScholes
Model and AssetTree
Pricer for Standard Trinomial Tree
This example shows the workflow to price an Barrier
instrument when you use a BlackScholes
model and an AssetTree
pricing method using a Standard Trinomial (STT) tree.
Create Barrier
Instrument Object
Use fininstrument
to create an Barrier
instrument object.
BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue',40,'Name',"barrier_option")
BarrierOpt = Barrier with properties: OptionType: "call" Strike: 45 BarrierType: "do" BarrierValue: 40 Rebate: 0 ExerciseStyle: "american" ExerciseDate: 01-Jan-2019 Name: "barrier_option"
Create BlackScholes
Model Object
Use finmodel
to create a BlackScholes
model object.
BlackScholesModel = finmodel("BlackScholes",'Volatility',0.30)
BlackScholesModel = BlackScholes with properties: Volatility: 0.3000 Correlation: 1
Create ratecurve
Object
Create a flat ratecurve
object using ratecurve
.
Settle = datetime(2018,1,1); Maturity = datetime(2023,1,1); Rate = 0.035; myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)
myRC = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 1 Dates: 01-Jan-2023 Rates: 0.0350 Settle: 01-Jan-2018 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous"
Create AssetTree
Pricer Object
Use finpricer
to create an AssetTree
pricer object with a Standard Trinomial (STT) equity tree and use the ratecurve
object for the 'DiscountCurve'
name-value pair argument.
NumPeriods = 15; STTPricer = finpricer("AssetTree",'DiscountCurve',myRC,'Model',BlackScholesModel,'SpotPrice',1000,'PricingMethod',"StandardTrinomial",'Maturity',datetime(2019,1,1),'NumPeriods',NumPeriods)
STTPricer = STTree with properties: Tree: [1x1 struct] NumPeriods: 15 Model: [1x1 finmodel.BlackScholes] DiscountCurve: [1x1 ratecurve] SpotPrice: 1000 DividendType: "continuous" DividendValue: 0 TreeDates: [25-Jan-2018 08:00:00 18-Feb-2018 16:00:00 15-Mar-2018 00:00:00 08-Apr-2018 08:00:00 02-May-2018 16:00:00 27-May-2018 00:00:00 20-Jun-2018 08:00:00 14-Jul-2018 16:00:00 ... ] (1x15 datetime)
STTPricer.Tree
ans = struct with fields:
ATree: {1x16 cell}
Probs: {[3x1 double] [3x3 double] [3x5 double] [3x7 double] [3x9 double] [3x11 double] [3x13 double] [3x15 double] [3x17 double] [3x19 double] [3x21 double] [3x23 double] [3x25 double] [3x27 double] [3x29 double]}
dObs: [01-Jan-2018 00:00:00 25-Jan-2018 08:00:00 18-Feb-2018 16:00:00 15-Mar-2018 00:00:00 08-Apr-2018 08:00:00 02-May-2018 16:00:00 27-May-2018 00:00:00 20-Jun-2018 08:00:00 14-Jul-2018 16:00:00 ... ] (1x16 datetime)
tObs: [0 0.0667 0.1333 0.2000 0.2667 0.3333 0.4000 0.4667 0.5333 0.6000 0.6667 0.7333 0.8000 0.8667 0.9333 1]
Price Barrier
Instrument
Use price
to compute the price and sensitivities for the Barrier
instrument.
[Price, outPR] = price(STTPricer,BarrierOpt,["all"])
Price = 956.5444
outPR = priceresult with properties: Results: [1x7 table] PricerData: [1x1 struct]
outPR.Results
ans=1×7 table
Price Delta Gamma Vega Lambda Rho Theta
______ _____ ___________ ________ ______ ______ ______
956.54 1 -1.9331e-17 -0.20023 1.0454 44.112 -1.514
outPR.PricerData.PriceTree
ans = struct with fields:
PTree: {1x16 cell}
ExTree: {1x16 cell}
tObs: [0 0.0667 0.1333 0.2000 0.2667 0.3333 0.4000 0.4667 0.5333 0.6000 0.6667 0.7333 0.8000 0.8667 0.9333 1]
dObs: [01-Jan-2018 25-Jan-2018 18-Feb-2018 15-Mar-2018 08-Apr-2018 02-May-2018 27-May-2018 20-Jun-2018 14-Jul-2018 08-Aug-2018 01-Sep-2018 25-Sep-2018 20-Oct-2018 13-Nov-2018 07-Dec-2018 01-Jan-2019]
Probs: {[3x1 double] [3x3 double] [3x5 double] [3x7 double] [3x9 double] [3x11 double] [3x13 double] [3x15 double] [3x17 double] [3x19 double] [3x21 double] [3x23 double] [3x25 double] [3x27 double] [3x29 double]}
Price Barrier
Instrument Using BlackScholes
Model and AssetMonteCarlo
Pricer
This example shows the workflow to price an Barrier
instrument when you use a BlackScholes
model and a AssetMonteCarlo
pricing method.
Create Barrier
Instrument Object
Use fininstrument
to create an Barrier
instrument object.
BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue',40,'Name',"barrier_option")
BarrierOpt = Barrier with properties: OptionType: "call" Strike: 45 BarrierType: "do" BarrierValue: 40 Rebate: 0 ExerciseStyle: "american" ExerciseDate: 01-Jan-2019 Name: "barrier_option"
Create BlackScholes
Model Object
Use finmodel
to create a BlackScholes
model object.
BlackScholesModel = finmodel("BlackScholes",'Volatility',0.30)
BlackScholesModel = BlackScholes with properties: Volatility: 0.3000 Correlation: 1
Create ratecurve
Object
Create a flat ratecurve
object using ratecurve
.
Settle = datetime(2018,1,1); Maturity = datetime(2023,1,1); Rate = 0.035; myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)
myRC = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 1 Dates: 01-Jan-2023 Rates: 0.0350 Settle: 01-Jan-2018 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous"
Create AssetMonteCarlo
Pricer Object
Use finpricer
to create an AssetMonteCarlo
pricer object and use the ratecurve
object for the 'DiscountCurve'
name-value pair argument.
outPricer = finpricer("AssetMonteCarlo",'DiscountCurve',myRC,"Model",BlackScholesModel,'SpotPrice',200,'simulationDates',datetime(2019,1,1))
outPricer = GBMMonteCarlo with properties: DiscountCurve: [1x1 ratecurve] SpotPrice: 200 SimulationDates: 01-Jan-2019 NumTrials: 1000 RandomNumbers: [] Model: [1x1 finmodel.BlackScholes] DividendType: "continuous" DividendValue: 0 MonteCarloMethod: "standard" BrownianMotionMethod: "standard"
Price Barrier
Instrument
Use price
to compute the price and sensitivities for the Barrier
instrument.
[Price, outPR] = price(outPricer,BarrierOpt,["all"])
Price = 156.6270
outPR = priceresult with properties: Results: [1x7 table] PricerData: [1x1 struct]
outPR.Results
ans=1×7 table
Price Delta Gamma Lambda Rho Theta Vega
______ ______ ___________ ______ _____ _____ _______
156.63 1.0004 -7.6028e-12 1.2774 43.45 0 0.67904
Price Barrier
Instrument Using BlackScholes
Model and AssetMonteCarlo
Pricer with Quasi-Monte Carlo Simulation
This example shows the workflow to price an Barrier
instrument when you use a BlackScholes
model and a AssetMonteCarlo
pricing method with quasi-Monte Carlo simulation.
Create Barrier
Instrument Object
Use fininstrument
to create an Barrier
instrument object.
BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue',40,'Name',"barrier_option")
BarrierOpt = Barrier with properties: OptionType: "call" Strike: 45 BarrierType: "do" BarrierValue: 40 Rebate: 0 ExerciseStyle: "american" ExerciseDate: 01-Jan-2019 Name: "barrier_option"
Create BlackScholes
Model Object
Use finmodel
to create a BlackScholes
model object.
BlackScholesModel = finmodel("BlackScholes",'Volatility',0.30)
BlackScholesModel = BlackScholes with properties: Volatility: 0.3000 Correlation: 1
Create ratecurve
Object
Create a flat ratecurve
object using ratecurve
.
Settle = datetime(2018,1,1); Maturity = datetime(2023,1,1); Rate = 0.035; myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)
myRC = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 1 Dates: 01-Jan-2023 Rates: 0.0350 Settle: 01-Jan-2018 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous"
Create AssetMonteCarlo
Pricer Object
Use finpricer
to create an AssetMonteCarlo
pricer object and use the ratecurve
object for the 'DiscountCurve'
name-value argument and use the name-value arguments for MonteCarloMethod
and BrownianMotionMethod
.
outPricer = finpricer("AssetMonteCarlo",'DiscountCurve',myRC,"Model",BlackScholesModel,'SpotPrice',200,'simulationDates',datetime(2019,1,1),'NumTrials',1e3, ... 'MonteCarloMethod',"quasi",'BrownianMotionMethod',"brownian-bridge")
outPricer = GBMMonteCarlo with properties: DiscountCurve: [1x1 ratecurve] SpotPrice: 200 SimulationDates: 01-Jan-2019 NumTrials: 1000 RandomNumbers: [] Model: [1x1 finmodel.BlackScholes] DividendType: "continuous" DividendValue: 0 MonteCarloMethod: "quasi" BrownianMotionMethod: "brownian-bridge"
Price Barrier
Instrument
Use price
to compute the price and sensitivities for the Barrier
instrument.
[Price, outPR] = price(outPricer,BarrierOpt,["all"])
Price = 156.2006
outPR = priceresult with properties: Results: [1x7 table] PricerData: [1x1 struct]
outPR.Results
ans=1×7 table
Price Delta Gamma Lambda Rho Theta Vega
_____ _______ ___________ ______ _____ _____ _______
156.2 0.99826 -4.7606e-13 1.2782 43.45 0 -1.5624
Price Barrier
Instrument Using Heston
Model and AssetMonteCarlo
Pricer
This example shows the workflow to price an Barrier
instrument when you use a Heston
model and an AssetMonteCarlo
pricing method.
Create Barrier
Instrument Object
Use fininstrument
to create an Barrier
instrument object.
BarrierOpt = fininstrument("Barrier",'Strike',45,'ExerciseDate',datetime(2019,1,1),'OptionType',"call",'ExerciseStyle',"american",'BarrierType',"DO",'BarrierValue',40,'Name',"barrier_option")
BarrierOpt = Barrier with properties: OptionType: "call" Strike: 45 BarrierType: "do" BarrierValue: 40 Rebate: 0 ExerciseStyle: "american" ExerciseDate: 01-Jan-2019 Name: "barrier_option"
Create Heston
Model Object
Use finmodel
to create a Heston
model object.
HestonModel = finmodel("Heston",'V0',0.032,'ThetaV',0.1,'Kappa',0.003,'SigmaV',0.2,'RhoSV',0.9)
HestonModel = Heston with properties: V0: 0.0320 ThetaV: 0.1000 Kappa: 0.0030 SigmaV: 0.2000 RhoSV: 0.9000
Create ratecurve
Object
Create a flat ratecurve
object using ratecurve
.
Settle = datetime(2018,1,1); Maturity = datetime(2023,1,1); Rate = 0.035; myRC = ratecurve('zero',Settle,Maturity,Rate,'Basis',1)
myRC = ratecurve with properties: Type: "zero" Compounding: -1 Basis: 1 Dates: 01-Jan-2023 Rates: 0.0350 Settle: 01-Jan-2018 InterpMethod: "linear" ShortExtrapMethod: "next" LongExtrapMethod: "previous"
Create AssetMonteCarlo
Pricer Object
Use finpricer
to create an AssetMonteCarlo
pricer object and use the ratecurve
object for the 'DiscountCurve'
name-value pair argument.
outPricer = finpricer("AssetMonteCarlo",'DiscountCurve',myRC,"Model",HestonModel,'SpotPrice',200,'simulationDates',datetime(2019,1,1))
outPricer = HestonMonteCarlo with properties: DiscountCurve: [1x1 ratecurve] SpotPrice: 200 SimulationDates: 01-Jan-2019 NumTrials: 1000 RandomNumbers: [] Model: [1x1 finmodel.Heston] DividendType: "continuous" DividendValue: 0 MonteCarloMethod: "standard" BrownianMotionMethod: "standard"
Price Barrier
Instrument
Use price
to compute the price and sensitivities for the Barrier
instrument.
[Price, outPR] = price(outPricer,BarrierOpt,["all"])
Price = 156.9962
outPR = priceresult with properties: Results: [1x8 table] PricerData: [1x1 struct]
outPR.Results
ans=1×8 table
Price Delta Gamma Lambda Rho Theta Vega VegaLT
_____ ______ _________ ______ _____ _____ ______ _________
157 1.0022 -1.08e-12 1.2768 43.45 0 2.7882 0.0013677
More About
Barrier Option
A barrier option has not only a strike price but also a barrier level and sometimes a rebate.
A barrier option has a predetermined barrier level that is set at a specific price above or below the current price of the underlying asset. The barrier can be either "up and in" or "down and in" for knock-in options, meaning the option becomes active if the price reaches or exceeds the barrier level. Conversely, it can be "up and out" or "down and out" for knock-out options, meaning the option becomes null and void if the price reaches or exceeds the barrier level.
The payoff for this type of option depends on whether the underlying asset crosses
the predetermined trigger value (barrier level), indicated by
BarrierValue
, during the life of the option. If the option
cannot be exercised because the barrier level either has or has not been reached, a
fixed rebate amount is paid. For more information, see Barrier Option.
Version History
Introduced in R2020aR2022b: Serial date numbers not recommended
Although Barrier
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.
See Also
Functions
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)