# optstocksensbyls

Calculate price and sensitivities for European, Bermudan, or American vanilla options using Monte Carlo simulations

## Syntax

## Description

returns vanilla option prices or sensitivities using the Longstaff-Schwartz model.
`PriceSens`

= optstocksensbyls(`RateSpec`

,`StockSpec`

,`OptSpec`

,`Strike`

,`Settle`

,`ExerciseDates`

)`optstocksensbyls`

computes prices or sensitivities of European,
Bermudan, and American vanilla options.

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

**Note**

Alternatively, you can use the `Vanilla`

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

adds
optional name-value pair arguments.`PriceSens`

= optstocksensbyls(___,`Name,Value`

)

## Examples

### Compute the Price and Sensitivities of a Vanilla Option

Define the `RateSpec`

.

StartDates = datetime(2013,1,1); EndDates = datetime(2015,1,1); Rates = 0.05; RateSpec = intenvset('ValuationDate', StartDates, 'StartDates', StartDates, ... 'EndDates', EndDates, 'Rates', Rates)

`RateSpec = `*struct with fields:*
FinObj: 'RateSpec'
Compounding: 2
Disc: 0.9060
Rates: 0.0500
EndTimes: 4
StartTimes: 0
EndDates: 735965
StartDates: 735235
ValuationDate: 735235
Basis: 0
EndMonthRule: 1

Define the `StockSpec`

for the asset.

```
AssetPrice = 100;
Sigma = 0.1;
DivType = 'continuous';
DivAmounts = 0.04;
StockSpec = stockspec(Sigma, AssetPrice, DivType, DivAmounts)
```

`StockSpec = `*struct with fields:*
FinObj: 'StockSpec'
Sigma: 0.1000
AssetPrice: 100
DividendType: {'continuous'}
DividendAmounts: 0.0400
ExDividendDates: []

Define the vanilla option.

```
OptSpec = 'call';
Settle = datetime(2013,1,1);
ExerciseDates = datetime(2015,1,1);
Strike = 105;
```

Compute the `Delta`

sensitivity for the vanilla option using the Longstaff-Schwartz model.

Antithetic = true; OutSpec = {'Delta'}; PriceSens = optstocksensbyls(RateSpec, StockSpec, OptSpec, Strike, ... Settle, ExerciseDates,'Antithetic', Antithetic, 'OutSpec', OutSpec)

PriceSens = 0.3945

To display the output for `Price`

, `Delta`

, `Path`

, and `Times`

, use the following:

OutSpec = {'Price','Delta'}; [Price, Delta, Path, Times] = optstocksensbyls(RateSpec, StockSpec, OptSpec, Strike, ... Settle, ExerciseDates,'Antithetic', Antithetic, 'OutSpec', OutSpec);

## Input Arguments

`StockSpec`

— Stock specification for underlying asset

structure

`OptSpec`

— Definition of option

character vector values `'call'`

or
`'put'`

Definition of option, specified as `'call'`

or
`'put'`

using a character vector.

**Data Types: **`char`

`Strike`

— Option strike price value

nonnegative scalar integer

Option strike price value, specified with a nonnegative scalar integer:

For a European option, use a scalar of strike price.

For a Bermuda option, use a

`1`

-by-`NSTRIKES`

vector of strike price.For an American option, use a scalar of strike price.

**Data Types: **`double`

`Settle`

— Settlement date or trade date

datetime scalar | string scalar | date character vector

Settlement date or trade date for the vanilla option, specified as a scalar datetime, string, or date character vector.

To support existing code, `optstocksensbyls`

also
accepts serial date numbers as inputs, but they are not recommended.

`ExerciseDates`

— Option exercise date

datetime array | string array | date character vector

Option exercise date, specified using a datetime array, string array, or date character vectors as follows:

For a European option, use a

`1`

-by-`1`

vector of dates. For a European option, there is only one`ExerciseDates`

on the option expiry date.For a Bermuda option, use a

`1`

-by-`NSTRIKES`

vector of dates.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, or if`ExerciseDates`

is a`1`

-by-`1`

cell array of character vectors, the option can be exercised between`Settle`

and the single listed`ExerciseDates`

.

To support existing code, `optstocksensbyls`

also
accepts serial date numbers as inputs, but they are not recommended.

### 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 = optstocksensbyls(RateSpec,StockSpec,
OptSpec,Strike,Settle,ExerciseDates,'AmericanOpt','1','NumTrials','2000','OutSpec',{'Price','Delta','Gamma'})
```

`AmericanOpt`

— Option type

`0`

European or Bermuda (default) | scalar with values `[0,1]`

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

and a positive integer scalar flag with values:

`0`

— European or Bermuda`1`

— American

**Note**

For American and Bermudan 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: **`single`

| `double`

`NumTrials`

— Simulation trials

`1000`

(default) | scalar

Simulation trials, specified as the comma-separated pair consisting of
`'NumTrials'`

and a scalar number of independent sample
paths.

**Data Types: **`double`

`NumPeriods`

— Simulation periods per trial

`100`

(default) | scalar

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

and a scalar number. `NumPeriods`

is considered only when pricing European vanilla options. For American and Bermuda
vanilla options, `NumPeriod`

is equal to the number of
`Exercise`

days during the life of the option.

**Data Types: **`double`

`Z`

— Dependent random variates

scalar | nonnegative integer

Dependent random variates used to generate the Brownian motion vector (that is,
Wiener processes) that drive the simulation, specified as the comma-separated pair
consisting of `'Z'`

and a
`NumPeriods`

-by-`1`

-by-`NumTrials`

3-D time series array.

**Data Types: **`single`

| `double`

`Antithetic`

— Indicator for antithetic sampling

`false`

(default) | 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`

`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 comma-separated pair consisting of
`'OutSpec'`

and a `NOUT`

- by-`1`

or `1`

-by-`NOUT`

cell array of character vectors
with possible values of `'Price'`

, `'Delta'`

,
`'Gamma'`

, `'Vega'`

, `'Lambda'`

,
`'Rho'`

, `'Theta'`

, and
`'All'`

.

`OutSpec = {'All'}`

specifies that the output should be
`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`

## Output Arguments

`PriceSens`

— Expected price or sensitivities of vanilla option

scalar

Expected price or sensitivities (defined by `OutSpec`

) of the
vanilla option, returned as a `1`

-by-`1`

array.

`Path`

— 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. 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`

— Dependent random variates

vector

Dependent random variates, if `Z`

is specified as an optional input
argument, the same value is returned. Otherwise, `Z`

contains the
random variates generated internally.

## More About

### Vanilla Option

A *vanilla option* is a category of options that
includes only the most standard components.

A vanilla option has an expiration date and straightforward strike price. American-style options and European-style options are both categorized as vanilla options.

The payoff for a vanilla option is as follows:

For a call: $$\mathrm{max}(St-K,0)$$

For a put: $$\mathrm{max}(K-St,0)$$

where:

*St* is the price of the underlying asset at time
*t*.

*K* is the strike price.

For more information, see Vanilla Option.

## Version History

**Introduced in R2013b**

### R2022b: Serial date numbers not recommended

Although `optstocksensbyls`

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.

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