Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

**MathWorks Machine Translation**

The automated translation of this page is provided by a general purpose third party translator tool.

MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.

Price option given simulated underlying values

`Price = optpricebysim(RateSpec,SimulatedPrices,Times,OptSpec,Strike,ExerciseTimes)`

`Price = optpricebysim(___,Name,Value)`

calculates the price of European, American, and Berumdan call/put options based on
risk-neutral simulation of the underlying asset. For American and Bermudan options, the
Longstaff-Schwartz least squares method calculates the early exercise premium.`Price`

= optpricebysim(`RateSpec`

,`SimulatedPrices`

,`Times`

,`OptSpec`

,`Strike`

,`ExerciseTimes`

)

adds optional name-value pair arguments.`Price`

= optpricebysim(___,`Name,Value`

)

Define the option.

S0 = 100; % Initial price of underlying asset Sigma = .2; % Volatility of underlying asset Strike = 110; % Strike OptSpec = 'call'; % Call option Settle = '1-Jan-2013'; % Settlement date of option Maturity = '1-Jan-2014'; % Maturity date of option r = .05; % Risk-free rate (annual, continuous compounding) Compounding = -1; % Continuous compounding Basis = 0; % Act/Act day count convention T = yearfrac(Settle, Maturity, Basis); % Time to expiration in years

Set up the `gbm`

object and run the Monte Carlo simulation based on Geometric Brownian Motion (GBM) using the `simBySolution`

method from Financial Toolbox™.

NTRIALS = 1000; NPERIODS = daysact(Settle, Maturity); dt = T/NPERIODS; OptionGBM = gbm(r, Sigma, 'StartState', S0); [Paths, Times, Z] = simBySolution(OptionGBM, NPERIODS, ... 'NTRIALS',NTRIALS, 'DeltaTime',dt,'Antithetic',true);

Create the interest-rate term structure to define `RateSpec`

.

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

`RateSpec = `*struct with fields:*
FinObj: 'RateSpec'
Compounding: -1
Disc: 0.9512
Rates: 0.0500
EndTimes: 1
StartTimes: 0
EndDates: 735600
StartDates: 735235
ValuationDate: 735235
Basis: 0
EndMonthRule: 1

Price an American option.

SimulatedPrices = squeeze(Paths); OptPrice = optpricebysim(RateSpec, SimulatedPrices, Times, OptSpec, ... Strike, T, 'AmericanOpt', 1)

OptPrice = 6.2028

Define the option.

S0 = 100; % Initial price of underlying asset Sigma = .2; % Volatility of underlying asset Strike = 110; % Strike OptSpec = 'call'; % Call option Settle = '1-Jan-2013'; % Settlement date of option Maturity = '1-Jan-2014'; % Maturity date of option r = .05; % Risk-free rate (annual, continuous compounding) Compounding = -1; % Continuous compounding Basis = 0; % Act/Act day count convention T = yearfrac(Settle, Maturity, Basis); % Time to expiration in years

Set up the `gbm`

object and run the Monte Carlo simulation based on Geometric Brownian Motion (GBM) using the `simBySolution`

method from Financial Toolbox™.

NTRIALS = 1000; NPERIODS = daysact(Settle, Maturity); dt = T/NPERIODS; OptionGBM = gbm(r, Sigma, 'StartState', S0); [Paths, Times, Z] = simBySolution(OptionGBM, NPERIODS, ... 'NTRIALS',NTRIALS, 'DeltaTime',dt,'Antithetic',true);

Create the interest-rate term structure to define `RateSpec`

.

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

`RateSpec = `*struct with fields:*
FinObj: 'RateSpec'
Compounding: -1
Disc: 0.9512
Rates: 0.0500
EndTimes: 1
StartTimes: 0
EndDates: 735600
StartDates: 735235
ValuationDate: 735235
Basis: 0
EndMonthRule: 1

Price an American Asian option (arithmetic mean) by finding the average price over periods.

AvgPrices = zeros(NPERIODS+1, NTRIALS); for i = 1:NPERIODS+1 AvgPrices(i,:) = mean(squeeze(Paths(1:i,:,:))); end AsianPrice = optpricebysim(RateSpec, AvgPrices, Times, OptSpec, ... Strike, T, 'AmericanOpt', 1)

AsianPrice = 1.8540

Define the option.

S0 = 100; % Initial price of underlying asset Sigma = .2; % Volatility of underlying asset Strike = 110; % Strike OptSpec = 'call'; % Call option Settle = '1-Jan-2013'; % Settlement date of option Maturity = '1-Jan-2014'; % Maturity date of option r = .05; % Risk-free rate (annual, continuous compounding) Compounding = -1; % Continuous compounding Basis = 0; % Act/Act day count convention T = yearfrac(Settle, Maturity, Basis); % Time to expiration in years

Set up the `gbm`

object and run the Monte Carlo simulation based on Geometric Brownian Motion (GBM) using the `simBySolution`

method from Financial Toolbox™.

NTRIALS = 1000; NPERIODS = daysact(Settle, Maturity); dt = T/NPERIODS; OptionGBM = gbm(r, Sigma, 'StartState', S0); [Paths, Times, Z] = simBySolution(OptionGBM, NPERIODS, ... 'NTRIALS',NTRIALS, 'DeltaTime',dt,'Antithetic',true);

Create the interest-rate term structure to define `RateSpec`

.

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

`RateSpec = `*struct with fields:*
FinObj: 'RateSpec'
Compounding: -1
Disc: 0.9512
Rates: 0.0500
EndTimes: 1
StartTimes: 0
EndDates: 735600
StartDates: 735235
ValuationDate: 735235
Basis: 0
EndMonthRule: 1

Price an American lookback option by finding the maximum price over periods.

MaxPrices = zeros(NPERIODS+1, NTRIALS); LastPrice = squeeze(Paths(1,:,:))'; for i = 1:NPERIODS+1; MaxPrices(i,:) = max([LastPrice; Paths(i,:)]); LastPrice = MaxPrices(i,:); end LookbackPrice = optpricebysim(RateSpec, MaxPrices, Times, OptSpec, ... Strike, T, 'AmericanOpt', 1)

LookbackPrice = 10.4084

Define the option.

S0 = 80; % Initial price of underlying asset Sigma = .3; % Volatility of underlying asset Strike = 75; % Strike OptSpec = 'put'; % Put option Settle = '1-Jan-2013'; % Settlement date of option Maturity = '1-Jan-2014'; % Maturity date of option ExerciseDates = {'1-Jun-2013', '1-Jan-2014'}; % Exercise dates of option r = .05; % Risk-free rate (annual, continuous compounding) Compounding = -1; % Continuous compounding Basis = 0; % Act/Act day count convention T = yearfrac(Settle, Maturity, Basis); % Time to expiration in years ExerciseTimes = yearfrac(Settle, ExerciseDates, Basis)'; % Exercise times

`gbm`

object and run the Monte Carlo simulation based on Geometric Brownian Motion (GBM) using the `simBySolution`

method from Financial Toolbox™.

Create the interest-rate term structure to define `RateSpec`

.

`RateSpec = `*struct with fields:*
FinObj: 'RateSpec'
Compounding: -1
Disc: 0.9512
Rates: 0.0500
EndTimes: 1
StartTimes: 0
EndDates: 735600
StartDates: 735235
ValuationDate: 735235
Basis: 0
EndMonthRule: 1

Price the Bermudan option.

```
SimulatedPrices = squeeze(Paths);
BermudanPrice = optpricebysim(RateSpec, SimulatedPrices, Times, ...
OptSpec, Strike, ExerciseTimes)
```

BermudanPrice = 5.3950

Define the option.

S1 = 110; % Price of first underlying asset S2 = 100; % Price of second underlying asset Sigma1 = .1; % Volatility of first underlying asset Sigma2 = .15; % Volatility of second underlying asset Strike = 15; % Strike Rho = .3; % Correlation between underlyings OptSpec = 'put'; % Put option Settle = '1-Jan-2013'; % Settlement date of option Maturity = '1-Jan-2014'; % Maturity date of option r = .05; % Risk-free rate (annual, continuous compounding) Compounding = -1; % Continuous compounding Basis = 0; % Act/Act day count convention T = yearfrac(Settle, Maturity, Basis); % Time to expiration in years

`gbm`

object and run the Monte Carlo simulation based on Geometric Brownian Motion (GBM) using the `simBySolution`

method from Financial Toolbox™.

NTRIALS = 1000; NPERIODS = daysact(Settle, Maturity); dt = T/NPERIODS; SpreadGBM = gbm(r*eye(2), diag([Sigma1;Sigma2]),'Correlation',... [1 Rho;Rho 1],'StartState',[S1;S2]); [Paths, Times, Z] = simBySolution(SpreadGBM, NPERIODS,'NTRIALS',NTRIALS,... 'DeltaTime',dt,'Antithetic',true);

Create the interest-rate term structure to define `RateSpec`

.

`RateSpec = `*struct with fields:*
FinObj: 'RateSpec'
Compounding: -1
Disc: 0.9512
Rates: 0.0500
EndTimes: 1
StartTimes: 0
EndDates: 735600
StartDates: 735235
ValuationDate: 735235
Basis: 0
EndMonthRule: 1

Price the American spread option.

Spread = squeeze(Paths(:,1,:) - Paths(:,2,:)); SpreadPrice = optpricebysim(RateSpec, Spread, Times, OptSpec, Strike, ... T, 'AmericanOpt', 1)

SpreadPrice = 9.0007

`RateSpec`

— Interest-rate term structure of risk-free ratesstructure

Interest-rate term structure of risk-free rates (annualized and continuously
compounded), specified by the `RateSpec`

obtained from `intenvset`

. The valuation date must be at the settlement date of the
option, and the day-count basis and end-of-month rule must be the same as those used to
calculate the `Times`

input. For information on the interest-rate
specification, see `intenvset`

.

**Data Types: **`struct`

`SimulatedPrices`

— Simulated pricesmatrix

Simulated prices, specified using a (`NumPeriods`

+
`1`

)-by-`NumTrials`

matrix of risk-neutral simulated
prices. The first element of `SimulatedPrices`

is the initial value
at time 0.

**Data Types: **`single`

| `double`

`Times`

— Annual time factors associated with simulated pricesvector

Annual time factors associated with simulated prices, specified using a
(`NumPeriods`

+ `1`

)-by-`1`

column
vector. Each element of `Times`

is associated with the corresponding
row of `SimulatedPrices`

. The first element of
`Times`

must be 0 (current time).

**Data Types: **`single`

| `double`

`OptSpec`

— Definition of option character vector with values

`'call'`

or
`'put'`

Definition of option as `'call'`

or `'put'`

,
specified as a character vector.

**Data Types: **`char`

`Strike`

— Option strike price valuesscalar | function handle

Option strike price values, specified as a scalar value `Strike`

price. `Strike`

for Bermudan options can be specified as a
`1`

-by-`NSTRIKES`

vector or a function handle that
returns the value of the strike given the time of the strike.

**Data Types: **`single`

| `double`

| `function_handle`

`ExerciseTimes`

— Exercise time for optionvector of exercise times

Exercise time for the option, specified as a vector of exercise times as follows:

For a European or Bermudan option,

`ExerciseTimes`

is a`1`

-by-`1`

(European) or`1`

-by-`NSTRIKES`

(Bermudan) vector of exercise times. For a European option, there is only one`ExerciseTimes`

on the option expiry date.For an American option,

`ExerciseTimes`

is a`1`

-by-`2`

vector of exercise time boundaries. The option exercises on any date between, or including, the pair of times on that row. If`ExerciseTimes`

is`1`

-by-`1`

, the option exercises between time`0`

and the single listed`ExerciseTimes`

.

**Data Types: **`double`

Specify optional
comma-separated pairs of `Name,Value`

arguments. `Name`

is
the argument name and `Value`

is the corresponding value.
`Name`

must appear inside quotes. You can specify several name and value
pair arguments in any order as
`Name1,Value1,...,NameN,ValueN`

.

```
Price =
optpricebysim(RateSpec,Prices,Times,OptSpec,Settle,Strike,ExerciseTimes,'AmericanOpt',1)
```

`'AmericanOpt'`

— Option type`0`

European or Bermudan (default) | scalar flag with value `[0,1]`

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

and an integer scalar flag with values:

`0`

— European or Bermudan`1`

— American

For American options, the Longstaff-Schwartz least squares method calculates the early exercise premium.

**Data Types: **`single`

| `double`

`Price`

— Price of optionscalar

Price of the option, returned as a scalar value.

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.

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: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

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