optpricebysim
Price option given simulated underlying values
Syntax
Description
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
)
Examples
Compute the Price of an American Option Using Monte Carlo Simulation Based on Geometric Brownian Motion
Define the option.
S0 = 100; % Initial price of underlying asset Sigma = .2; % Volatility of underlying asset Strike = 110; % Strike OptSpec = 'call'; % Call option Settle = datetime(2013,1,1); % Settlement date of option Maturity = datetime(2014,1,1); % 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 = 5.8172
Compute the Price of an American Asian Option Using Monte Carlo Simulation Based on Geometric Brownian Motion
Define the option.
S0 = 100; % Initial price of underlying asset Sigma = .2; % Volatility of underlying asset Strike = 110; % Strike OptSpec = 'call'; % Call option Settle = datetime(2013,1,1); % Settlement date of option Maturity = datetime(2014,1,1); % 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.8221
Compute the Price of an American Lookback Option Using Monte Carlo Simulation Based on Geometric Brownian Motion
Define the option.
S0 = 100; % Initial price of underlying asset Sigma = .2; % Volatility of underlying asset Strike = 110; % Strike OptSpec = 'call'; % Call option Settle = datetime(2013,1,1); % Settlement date of option Maturity = datetime(2014,1,1); % 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.4410
Compute the Price of a Bermudan Option Using Monte Carlo Simulation Based on Geometric Brownian Motion
Define the option.
S0 = 80; % Initial price of underlying asset Sigma = .3; % Volatility of underlying asset Strike = 75; % Strike OptSpec = 'put'; % Put option Settle = datetime(2013,1,1); % Settlement date of option Maturity = datetime(2014,1,1); % Maturity date of option ExerciseDates = [datetime(2013,1,1) , datetime(2014,1,1)]; % 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 = 4.9889
Compute the Price of an American Spread Option Using Monte Carlo Simulation Based on Geometric Brownian Motion
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 = datetime(2013,1,1); % Settlement date of option Maturity = datetime(2014,1,1); % 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; 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 = 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 American spread option.
Spread = squeeze(Paths(:,1,:) - Paths(:,2,:)); SpreadPrice = optpricebysim(RateSpec, Spread, Times, OptSpec, Strike, ... T, 'AmericanOpt', 1)
SpreadPrice = 9.0007
Input Arguments
RateSpec
— Interest-rate term structure of risk-free rates
structure
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 prices
matrix
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: double
Times
— Annual time factors associated with simulated prices
vector
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: 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 values
scalar | 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: double
| function_handle
ExerciseTimes
— Exercise time for option
datetime array | string array | date character vector
Exercise time for the option, specified as a datetime array, string array, or date character vectors, as follows:
For a European or Bermudan option,
ExerciseTimes
is a1
-by-1
(European) or1
-by-NSTRIKES
(Bermudan) vector of exercise times. For a European option, there is only oneExerciseTimes
on the option expiry date.For an American option,
ExerciseTimes
is a1
-by-2
vector of exercise time boundaries. The option exercises on any date between, or including, the pair of times on that row. IfExerciseTimes
is1
-by-1
, the option exercises between time0
and the single listedExerciseTimes
.
To support existing code, optpricebysim
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 =
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 Bermudan1
— American
For American options, the Longstaff-Schwartz least squares method calculates the early exercise premium.
Data Types: double
Output Arguments
Price
— Price of option
scalar
Price of the option, returned as a scalar value.
Version History
Introduced in R2014aR2022b: Serial date numbers not recommended
Although optpricebysim
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)