# barrierbyls

Price European or American barrier options using Monte Carlo simulations

## Syntax

## Description

`[`

calculates barrier option prices on a single underlying asset using the Longstaff-Schwartz
model. `Price`

,`Paths`

,`Times`

,`Z`

]
= barrierbyls(`RateSpec`

,`StockSpec`

,`OptSpec`

,`Strike`

,`Settle`

,`ExerciseDates`

,`BarrierSpec`

,`Barrier`

)`barrierbyls`

computes prices of European and American barrier
options.

For American options, the Longstaff-Schwartz least squares method is used to calculate the early exercise premium.

**Note**

Alternatively, you can use the `Barrier`

object to price
Barrier options. For more information, see Get Started with Workflows Using Object-Based Framework for Pricing Financial Instruments.

## Examples

### Price an American Barrier Down In Put Option

Compute the price of an American down in put option using the following data:

Rates = 0.0325; Settle = datetime(2016,1,1); Maturity = datetime(2017,1,1); Compounding = -1; Basis = 1;

Define a `RateSpec`

.

RateSpec = intenvset('ValuationDate',Settle,'StartDates',Settle,'EndDates',Maturity, ... 'Rates',Rates,'Compounding',Compounding,'Basis',Basis)

`RateSpec = `*struct with fields:*
FinObj: 'RateSpec'
Compounding: -1
Disc: 0.9680
Rates: 0.0325
EndTimes: 1
StartTimes: 0
EndDates: 736696
StartDates: 736330
ValuationDate: 736330
Basis: 1
EndMonthRule: 1

Define a `StockSpec`

.

AssetPrice = 40; Volatility = 0.20; StockSpec = stockspec(Volatility,AssetPrice)

`StockSpec = `*struct with fields:*
FinObj: 'StockSpec'
Sigma: 0.2000
AssetPrice: 40
DividendType: []
DividendAmounts: 0
ExDividendDates: []

Calculate the price of an American barrier down in put option.

Strike = 45; OptSpec = 'put'; Barrier = 35; BarrierSpec = 'DI'; AmericanOpt = 1; Price = barrierbyls(RateSpec,StockSpec,OptSpec,Strike,Settle,Maturity,BarrierSpec,... Barrier,'NumTrials',2000,'AmericanOpt',AmericanOpt)

Price = 4.7306

## 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 the option as `'call'`

or `'put'`

, specified
as a character vector or string array with a value of `"call"`

or
`"put"`

.

**Data Types: **`char`

| `string`

`Strike`

— Option strike price value

scalar 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, `barrierbyls`

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`

-by-`2`

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 non-`NaN`

date is listed, the option can be exercised between`Settle`

and the single listed date in`ExerciseDates`

.

To support existing code, `barrierbyls`

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 Knock-inThis 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.

`'UO'`

— Up Knock-outThis 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 up-and-out option, the rebate is paid if the spot price of the underlying reaches or exceeds the barrier level.

`'DI'`

— Down Knock-inThis 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 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.

`'DO'`

— Down Knock-upThis 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 Knock-out | Worthless | Standard Call/Put |

Call/Put | Down Knock-in | Call/Put | Worthless |

Call/Put | Up Knock-out | Worthless | Standard Call/Put |

Call/Put | Up Knock-in | Standard Call/Put | Worthless |

**Data Types: **`char`

`Barrier`

— Barrier level

scalar numeric

Barrier level, specified as a scalar numeric.

**Data Types: **`double`

### Name-Value Arguments

Specify 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: **`Price = barrierbyls(RateSpec,StockSpec,OptSpec,Strike,Settle,Maturity,BarrierSpec,Barrier,Rebate,1000)`

`AmericanOpt`

— Option type

`0`

(European) (default) | values `[0,1]`

Option type, specified as the comma-separated pair consisting of
`'AnericanOpt'`

and a
`NINST`

-by-`1`

positive integer scalar flags with
values:

`0`

— European`1`

— American

**Note**

For American options, the Longstaff-Schwartz least squares method is used to calculate the early exercise premium. For more information on the least squares method, see https://people.math.ethz.ch/%7Ehjfurrer/teaching/LongstaffSchwartzAmericanOptionsLeastSquareMonteCarlo.pdf.

**Data Types: **`double`

`Rebate`

— Rebate value

`0`

(default) | scalar numeric

Rebate value, specified as the comma-separated pair consisting of `'Rebate'`

and a scalar numeric. For Knock-in options, the `Rebate`

is paid at
expiry. For Knock-out options, the `Rebate`

is paid when the
`Barrier`

is reached.

**Data Types: **`double`

`NumTrials`

— Number of independent sample paths

`1000`

(default) | nonnegative integer

Number of independent sample paths (simulation trials), specified as the
comma-separated pair consisting of `'NumTrials'`

and a scalar
nonnegative integer.

**Data Types: **`double`

`NumPeriods`

— Number of simulation periods per trial

`100`

(default) | nonnegative integer

Number of simulation periods per trial, specified as the comma-separated pair
consisting of `'NumPeriods'`

and a scalar nonnegative integer.

**Data Types: **`double`

`Z`

— Time series array of dependent random variates

vector

Time series array of dependent random variates, specified as the comma-separated pair
consisting of `'Z'`

and a
`NumPeriods`

-by-`1`

-by-`NumTrials`

3-D time series array. The `Z`

value generates the Brownian motion
vector (that is, Wiener processes) that drives the simulation.

**Data Types: **`double`

`Antithetic`

— Indicator for antithetic sampling

`false`

(default) | scalar logical flag with value of `true`

or `false`

Indicator for antithetic sampling, specified as the comma-separated pair consisting of
`'Antithetic'`

and a value of `true`

or
`false`

.

**Data Types: **`logical`

## Output Arguments

`Price`

— Expected prices for barrier options

matrix

Expected prices for barrier options, returned as a `NINST`

-by-`1`

matrix.

`Paths`

— Simulated paths of correlated state variables

vector

Simulated paths of correlated state variables, returned as a ```
NumPeriods
+ 1
```

-by-`1`

-by-`NumTrials`

3-D
time series array of simulated paths of correlated state variables.
Each row of `Paths`

is the transpose of the state
vector *X*(*t*) at time *t* for
a given trial.

`Times`

— Observation times associated with simulated paths

vector

Observation times associated with simulated paths, returned
as a `NumPeriods + 1`

-by-`1`

column
vector of observation times associated with the simulated paths. Each
element of `Times`

is associated with the corresponding
row of `Paths`

.

`Z`

— Time series array of dependent random variates

vector

Time series array of dependent random variates, returned as a
`NumPeriods`

-by-`1`

-by-`NumTrials`

3-D array when `Z`

is specified as an input argument. If the
`Z`

input argument is not specified, then the `Z`

output argument contains the random variates generated internally.

## 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 knock-in 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 R2016b**

### R2022b: Serial date numbers not recommended

Although `barrierbyls`

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

`barrierbyfd`

| `barriersensbyfd`

| `barrierbybls`

| `barriersensbybls`

| `barriersensbyls`

| `Barrier`

## 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)