# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# optpricebysim

Price option given simulated underlying values

## Syntax

Price = optpricebysim(RateSpec,SimulatedPrices,Times,OptSpec,Strike,ExerciseTimes)
Price = optpricebysim(___,Name,Value)

## Description

example

Price = optpricebysim(RateSpec,SimulatedPrices,Times,OptSpec,Strike,ExerciseTimes) 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.

example

Price = optpricebysim(___,Name,Value) adds optional name-value pair arguments.

## Examples

collapse all

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

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

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;
[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 = 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

T, 'AmericanOpt', 1)

## Input Arguments

collapse all

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

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

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

Definition of option as 'call' or 'put', specified as a character vector.

Data Types: char

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

Exercise time for the option, specified as date character vectors or serial date numbers 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 | char | cell

### Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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

collapse all

Option type, specified as an integer scalar flag with these 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

## Output Arguments

collapse all

Price of the option, returned as a scalar value.