naginterfaces.library.specfun.opt_​imp_​vol

naginterfaces.library.specfun.opt_imp_vol(calput, p, k, s0, t, r, mode=1)[source]

opt_imp_vol computes the implied volatility of a European option contract based on the Black–Scholes–Merton formula.

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

https://www.nag.com/numeric/nl/nagdoc_28.6/flhtml/s/s30acf.html

Parameters
calputstr, length 1

Determines whether the option is a call or a put.

A call; the holder has a right to buy.

A put; the holder has a right to sell.

pfloat, array-like, shape

must contain , the th option price, for .

kfloat, array-like, shape

must contain , the th strike price, for .

s0float, array-like, shape

must contain , the th spot price, for .

tfloat, array-like, shape

must contain , the th time, in years, to maturity, for .

rfloat, array-like, shape

must contain , the th interest rate, for . Note that a rate of 5% should be entered as 0.05.

modeint, optional

Specifies which algorithm will be used to compute the implied volatilities. See Accuracy and Parallelism and Performance for further guidance on the choice of mode.

The Glau et al. (2018) algorithm will be used. The nodes used in the Chebyshev interpolation will be chosen to achieve relative accuracy to approximately seven decimal places;

The Glau et al. (2018) algorithm will be used. The nodes used in the Chebyshev interpolation will be chosen to achieve relative accuracy to approximately decimal places, but limited by the machine precision;

The Jäckel (2015) algorithm will be used, aiming for accuracy to approximately decimal places, but limited by machine precision.

Returns
sigmafloat, ndarray, shape

contains , the th implied volatility, for .

ivalidint, ndarray, shape

indicates any errors with the input arguments that prevented from being computed. If , contains .

No error.

.

.

.

.

The combination of , , , and is out of the domain in which can be computed. See Further Comments for further details.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: , or .

(errno )

On entry, .

Constraint: .

Warns
NagAlgorithmicWarning
(errno )

On entry at least one input argument was invalid.

Check for more information.

Notes

The Black–Scholes formula for the price of a European option is

for a call option, and

for a put option, where is the cumulative Normal distribution function, is the time to maturity, is the spot price of the underlying asset, is the strike price, is the interest rate and is the volatility.

Given arrays of values , , , and , for , opt_imp_vol computes the implied volatilities .

opt_imp_vol offers the choice of two algorithms. The algorithm of Glau et al. (2018) uses Chebyshev interpolation to compute the implied volatilities, and performs best for long arrays of input data. The algorithm of Jäckel (2015) uses a third order Householder iteration and performs better for short arrays of input data.

References

Glau, K, Herold, P, Madan, D B and Pötz, C, 2018, The Chebyshev method for the implied volatility, Accepted for publication in the Journal of Computational Finance

Jäckel, P, 2015, Let’s be Rational, Wilmott Magazine (2015(75)), 40–53