The function may be called by the names: s30acc or nag_specfun_opt_imp_vol.
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 , s30acc computes the implied volatilities .
s30acc 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.
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
Let's be Rational
1: – Nag_CallPutInput
On entry: 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.
2: – IntegerInput
On entry: , the number of implied volatilities to be computed.
3: – const doubleInput
On entry: must contain , the th option price, for .
, for .
4: – const doubleInput
On entry: must contain , the th strike price, for .
, for .
5: – const doubleInput
On entry: must contain , the th spot price, for .
, for .
6: – const doubleInput
On entry: must contain , the th time, in years, to maturity, for .
, for .
7: – const doubleInput
On entry: must contain , the th interest rate, for . Note that a rate of 5% should be entered as 0.05.
8: – doubleOutput
On exit: contains , the th implied volatility, for .
9: – IntegerInput
On entry: specifies which algorithm will be used to compute the implied volatilities. See Sections 7 and 8 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.
, or .
10: – IntegerOutput
On exit: indicates any errors with the input arguments that prevented from being computed. If , contains .
The combination of , , , and is out of the domain in which can be computed. See Section 9 for further details.
11: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument had an illegal value.
On entry, . Constraint: , or .
On entry, .
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
On entry at least one input argument was invalid. Check ivalid for more information.
If or then s30acc uses Chebyshev interpolation. For it aims for relative accuracy to roughly single precision (approximately seven decimal places). For it aims for relative accuracy to roughly double precision (approximately sixteen decimal places).
If , a Householder iteration is used to achieve relative accuracy to roughly double precision (approximately sixteen decimal places). In practice there is very little difference in accuracy between and , though for more extreme input values, is likely to be more accurate.
8Parallelism and Performance
s30acc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
When or , s30acc uses an algorithm optimized for performance on large vectors of input data () by exploiting vector instructions when available.
When , s30acc uses an algorithm optimized for performance on smaller vectors of input data.
Numerical experiments suggest that for , the best performance is always achieved by choosing , whereas for , or should be used, according to the desired accuracy.
The domain of inputs, , , , and , for which s30acc is able to accurately compute is very large and should cover all practical applications of this function. Thus, encountering arguments for which is returned is highly unlikely. Note that it is not possible to give a closed-form expression for the allowed range of arguments because this range is based on a transformation to the normalized call price.
Note that some formulations of the Black–Scholes equation also include the annual yield rate, . If you wish to incorporate here, then you must first compute the quantities , and . s30acc should then be called with , and in place of , and respectively.
s30acc can also be used with Black's model for European futures options. In this case, the forward price, , and the discount factor, , are used, which are related to via . In addition, the option price is scaled by a factor .
Approximately of real allocatable memory and of integer allocatable memory is required by the function.
This example reads in values of , , , and from a file, evaluates the implied volatilities, , and prints the results.