optstocksensbyfd
Calculate vanilla option prices or sensitivities using finite difference method
Syntax
Description
[
calculates
vanilla option prices or sensitivities using the finite difference
method. PriceSens
,PriceGrid
,AssetPrices
,Times
]
= optstocksensbyfd(RateSpec
,StockSpec
,OptSpec
,Strike
,Settle
,ExerciseDates
)
[
adds optional namevalue pair arguments. PriceSens
,PriceGrid
,AssetPrices
,Times
]
= optstocksensbyfd(___,Name,Value
)
Examples
Calculate the Price and Sensitivities for a Vanilla Call Option Using Finite Difference Method
Create a RateSpec
.
AssetPrice = 50; Strike = 45; Rate = 0.035; Volatility = 0.30; Settle = datetime(2015,1,1); Maturity = datetime(2016,1,1); Basis = 1; RateSpec = intenvset('ValuationDate',Settle,'StartDates',Settle,'EndDates',... Maturity,'Rates',Rate,'Compounding',1,'Basis',Basis)
RateSpec = struct with fields:
FinObj: 'RateSpec'
Compounding: 1
Disc: 0.9656
Rates: 0.0350
EndTimes: 1
StartTimes: 0
EndDates: 736330
StartDates: 735965
ValuationDate: 735965
Basis: 1
EndMonthRule: 1
Create a StockSpec
.
StockSpec = stockspec(Volatility,AssetPrice)
StockSpec = struct with fields:
FinObj: 'StockSpec'
Sigma: 0.3000
AssetPrice: 50
DividendType: []
DividendAmounts: 0
ExDividendDates: []
Calculate the price and sensitivities for of a European vanilla call option using the finite difference method.
ExerciseDates = datetime(2015,5,1); OptSpec = 'Call'; OutSpec = {'price'; 'delta'; 'theta'}; [PriceSens, Delta, Theta] = optstocksensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,... ExerciseDates,'OutSpec',OutSpec)
PriceSens = 6.7352
Delta = 0.7765
Theta = 4.9999
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 values 'call'
or
'put'
.
Data Types: char
 string
Strike
— Option strike price value
nonnegative scalar  nonnegative vector
Option strike price value, specified as a nonnegative scalar or vector.
For a European option, use a scalar of strike price.
For a Bermuda option, use a
1
byNSTRIKES
vector of strike prices.For an American option, use a scalar of strike price.
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, optstocksensbyfd
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 as follows:
For a European option, use a
1
by1
vector of dates. For a Bermuda option, use a1
byNSTRIKES
vector of dates.For an American option, use a
1
by2
vector of dates. The option can be exercised on any date between or including the pair of dates on that row. If only one nonNaN
date is listed, or ifExerciseDates
is a1
by1
cell array of date character vectors, the option can be exercised betweenSettle
and the single listed date inExerciseDates
.
To support existing code, optstocksensbyfd
also
accepts serial date numbers as inputs, but they are not recommended.
NameValue Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Namevalue 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: PriceSens = optstocksensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,ExerciseDates,'OutSpec',{'All'},'AssetGridSize',1000)
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 commaseparated pair consisting of
'OutSpec'
and a NOUT

by1
or a
1
byNOUT
cell array of
character vectors with possible values of 'Price'
,
'Delta'
, 'Gamma'
,
'Vega'
, 'Lambda'
,
'Rho'
, 'Theta'
, and
'All'
.
OutSpec = {'All'}
specifies that the output
is 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
AssetGridSize
— Size of asset grid used for finite difference grid
400
(default)  positive scalar
Size of asset grid used for finite difference grid, specified as the commaseparated pair
consisting of 'AssetGridSize'
and a positive
scalar.
Data Types: double
AssetPriceMax
— Maximum price for price grid boundary
if unspecified, StockSpec
values
are calculated using asset distributions at maturity (default)  positive scalar
Maximum price for price grid boundary, specified as the commaseparated pair consisting of
'AssetPriceMax'
and a positive scalar.
Data Types: single
 double
TimeGridSize
— Size of time grid used for finite difference grid
100
(default)  positive scalar
Size of the time grid used for a finite difference grid, specified as the commaseparated pair
consisting of 'TimeGridSize'
and a positive
scalar.
Data Types: double
AmericanOpt
— Option type
0
(European/Bermuda) (default)  scalar with values [0,1]
Option type, specified as the commaseparated pair consisting of
'AmericanOpt'
and
NINST
by1
positive integer
scalar flags with values:
0
— European/Bermuda1
— American
Data Types: double
Output Arguments
PriceSens
— Expected prices or sensitivities for vanilla options
scalar
Expected price or sensitivities (defined by OutSpec
)
of the vanilla option, returned as a 1
by1
array.
PriceGrid
— Grid containing prices calculated by finite difference method
grid
Grid containing prices calculated by the finite difference method,
returned as a twodimensional grid with size PriceGridSize*length(Times)
.
The number of columns does not have to be equal to the TimeGridSize
,
because exdividend dates in the StockSpec
are
added to the time grid. The price for t = 0
is
contained in PriceGrid(:, end)
.
Times
— Times corresponding to second dimension of PriceGrid
vector
Times corresponding to second dimension of the PriceGrid
,
returned as a vector.
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. Americanstyle options and Europeanstyle options are both categorized as vanilla options.
The payoff for a vanilla option is as follows:
For a call: $$\mathrm{max}(StK,0)$$
For a put: $$\mathrm{max}(KSt,0)$$
where:
St is the price of the underlying asset at time t.
K is the strike price.
For more information, see Vanilla Option.
References
[1] Haug, E. G., J. Haug, and A. Lewis. "Back to basics: a new approach to the discrete dividend problem." Vol. 9, Wilmott magazine, 2003, pp. 37–47.
[2] Wu, L. and Y. K. Kwok. "A frontfixing finite difference method for the valuation of American options." Journal of Financial Engineering. Vol. 6.4, 1997, pp. 83–97.
Version History
Introduced in R2016bR2022b: Serial date numbers not recommended
Although optstocksensbyfd
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)