naginterfaces.library.pde.dim1_​blackscholes_​fd

naginterfaces.library.pde.dim1_blackscholes_fd(kopt, x, mesh, s, t, tdpar, r, q, sigma, ntkeep, alpha=0.55)[source]

dim1_blackscholes_fd solves the Black–Scholes equation for financial option pricing using a finite difference scheme.

For full information please refer to the NAG Library document for d03nc

https://support.nag.com/numeric/nl/nagdoc_30.1/flhtml/d03/d03ncf.html

Parameters
koptint

Specifies the kind of option to be valued.

A European call option.

An American call option.

A European put option.

An American put option.

xfloat

The exercise price .

meshstr, length 1

Indicates the type of finite difference mesh to be used:

Uniform mesh.

Custom mesh supplied by you.

sfloat, array-like, shape

If , must contain the th stock price in the mesh, for . These values should be in increasing order, with and .

If , must be set to and to , but need not be initialized, as they will be set internally by the function in order to define a uniform mesh.

tfloat, array-like, shape

If then must contain the th time in the mesh, for . These values should be in increasing order, with and .

If then must be set to and to , but need not be initialized, as they will be set internally by the function in order to define a uniform mesh.

tdparbool, array-like, shape

Specifies whether or not various arguments are time-dependent. More precisely, is time-dependent if and constant otherwise. Similarly, specifies whether is time-dependent and specifies whether is time-dependent.

rfloat, array-like, shape

Note: the required length for this argument is determined as follows: if : ; otherwise: .

If then must contain the value of the risk-free interest rate at the th time in the mesh, for .

If then must contain the constant value of the risk-free interest rate .

The remaining elements need not be set.

qfloat, array-like, shape

Note: the required length for this argument is determined as follows: if : ; otherwise: .

If then must contain the value of the continuous dividend at the th time in the mesh, for .

If then must contain the constant value of the continuous dividend .

The remaining elements need not be set.

sigmafloat, array-like, shape

Note: the required length for this argument is determined as follows: if : ; otherwise: .

If then must contain the value of the volatility at the th time in the mesh, for .

If then must contain the constant value of the volatility .

The remaining elements need not be set.

ntkeepint

The number of solutions to be stored in the time direction. The function calculates the solution backwards from to at all times in the mesh. These time solutions and the corresponding Greeks will be stored at times , for , in the arrays , , , , and . Other time solutions will be discarded. To store all time solutions set .

alphafloat, optional

The value of to be used in the time-stepping scheme. Typical values include:

Explicit forward Euler scheme.

Implicit Crank–Nicolson scheme.

Implicit backward Euler scheme.

The value gives second-order accuracy in time.

Values greater than give unconditional stability.

Since is at the limit of unconditional stability this value does not damp oscillations.

Returns
sfloat, ndarray, shape

If , the elements of define a uniform mesh over .

If , the elements of are unchanged.

tfloat, ndarray, shape

If , the elements of define a uniform mesh over .

If , the elements of are unchanged.

ffloat, ndarray, shape

, for , for , contains the value of the option at the th mesh point at time .

thetafloat, ndarray, shape

The values of various Greeks at the th mesh point at time , as follows:

deltafloat, ndarray, shape

The values of various Greeks at the th mesh point at time , as follows:

gammafloat, ndarray, shape

The values of various Greeks at the th mesh point at time , as follows:

lamdafloat, ndarray, shape

The values of various Greeks at the th mesh point at time , as follows:

rhofloat, ndarray, shape

The values of various Greeks at the th mesh point at time , as follows:

Raises
NagValueError
(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: , , or .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: when , , for .

(errno )

On entry, .

Constraint: when , , for .

Notes

dim1_blackscholes_fd solves the Black–Scholes equation (see Hull (1989) and Wilmott et al. (1995))

for the value of a European or American, put or call stock option, with exercise price . In equation (1) is time, is the stock price, is the risk free interest rate, is the continuous dividend, and is the stock volatility. According to the values in the array , the arguments , and may each be either constant or functions of time. The function also returns values of various Greeks.

dim1_blackscholes_fd uses a finite difference method with a choice of time-stepping schemes. The method is explicit for and implicit for nonzero values of . Second order time accuracy can be obtained by setting . According to the value of the argument the finite difference mesh may be either uniform, or user-defined in both and directions.

References

Hull, J, 1989, Options, Futures and Other Derivative Securities, Prentice–Hall

Wilmott, P, Howison, S and Dewynne, J, 1995, The Mathematics of Financial Derivatives, Cambridge University Press