# Documentation

### This is machine translation

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

# optstocksensbyfd

Calculate vanilla option prices or sensitivities using finite difference method

## Syntax

``````[PriceSens,PriceGrid,AssetPrices,Times] = optstocksensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,ExerciseDates)``````
``````[PriceSens,PriceGrid,AssetPrices,Times] = optstocksensbyfd(___,Name,Value)``````

## Description

example

``````[PriceSens,PriceGrid,AssetPrices,Times] = optstocksensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,ExerciseDates)``` calculates vanilla option prices or sensitivities using the finite difference method. ```

example

``````[PriceSens,PriceGrid,AssetPrices,Times] = optstocksensbyfd(___,Name,Value)``` adds optional name-value pair arguments. ```

## Examples

collapse all

Create a `RateSpec`.

```AssetPrice = 50; Strike = 45; Rate = 0.035; Volatility = 0.30; Settle = '01-Jan-2015'; Maturity = '01-Jan-2016'; 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 = 'may-1-2015'; OptSpec = 'Call'; OutSpec = {'price'; 'delta'; 'theta'}; [PriceSens, Delta, Theta] = optstocksensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,... ExerciseDates,'OutSpec',OutSpec)```
```PriceSens = 6.7350 ```
```Delta = 0.7766 ```
```Theta = -4.9998 ```

## Input Arguments

collapse all

Interest-rate term structure (annualized and continuously compounded), specified by the `RateSpec` obtained from `intenvset`. For information on the interest-rate specification, see `intenvset`.

Data Types: `struct`

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`

Definition of the option as `'call'` or `'put'`, specified as a character vector or string object with values `'call'` or `'put'`.

Data Types: `char` | `string`

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`-by-`NSTRIKES` vector of strike prices.

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

Data Types: `single` | `double`

Settlement or trade date for the barrier option, specified as a serial date number, a date character vector, or a datetime object.

Data Types: `double` | `char` | `datetime`

Option exercise dates, specified as a nonnegative scalar integer, date character vector, or datetime object:

• For a European option, use a `1`-by-`1` vector of dates, specified as a nonnegative scalar integer, a date character vector, or a datetime object. For a Bermuda option, use a `1`-by-`NSTRIKES` vector of dates, specified as a nonnegative scalar integer, date character vector, or datetime object.

• For an American option, use a `1`-by-`2` cell array of date character vectors. 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` vector of serial date numbers or a cell array of date character vectors, the option can be exercised between `Settle` and the single listed date in `ExerciseDates`.

Data Types: `double` | `char` | `cell` | `datetime`

### 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: `PriceSens = optstocksensbyfd(RateSpec,StockSpec,OptSpec,Strike,Settle,ExerciseDates,'OutSpec',{'All'},'AssetGridSize',1000)`

collapse all

Define outputs, specifying a `NOUT`- by-`1` or a `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 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`

Size of asset grid used for finite difference grid, specified as a positive scalar.

Data Types: `double`

Maximum price for price grid boundary, specified by as a scalar.

Data Types: `single` | `double`

Size of the time grid used for a finite difference grid, specified as a positive scalar.

Data Types: `double`

Option type, specified as `NINST`-by-`1` positive integer scalar flags with values:

• `0` — European/Bermuda

• `1` — American

Data Types: `double`

## Output Arguments

collapse all

Expected price or sensitivities (defined by `OutSpec`) of the vanilla option, returned as a `1`-by-`1` array.

Grid containing prices calculated by the finite difference method, returned as a two-dimensional grid with size `PriceGridSize*length(Times)`. The number of columns does not have to be equal to the `TimeGridSize`, because ex-dividend dates in the `StockSpec` are added to the time grid. The price for `t = 0` is contained in `PriceGrid(:, end)`.

Prices of the asset defined by the `StockSpec` corresponding to the first dimension of `PriceGrid`, returned as a vector.

Times corresponding to second dimension of the `PriceGrid`, returned as a vector.

## 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 front-fixing finite difference method for the valuation of American options." Journal of Financial Engineering. Vol. 6.4, 1997, pp. 83–97.