The routine may be called by the names s30acf or nagf_specfun_opt_imp_vol.
3Description
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 , s30acf computes the implied volatilities .
s30acf 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.
4References
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 Magazine2015(75)
40–53
5Arguments
1: – Character(1)Input
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.
Constraint:
or .
2: – IntegerInput
On entry: , the number of implied volatilities to be computed.
Constraint:
.
3: – Real (Kind=nag_wp) arrayInput
On entry: must contain , the th option price, for .
Constraint:
, for .
4: – Real (Kind=nag_wp) arrayInput
On entry: must contain , the th strike price, for .
Constraint:
, for .
5: – Real (Kind=nag_wp) arrayInput
On entry: must contain , the th spot price, for .
Constraint:
, for .
6: – Real (Kind=nag_wp) arrayInput
On entry: must contain , the th time, in years, to maturity, for .
Constraint:
, for .
7: – Real (Kind=nag_wp) arrayInput
On entry: must contain , the th interest rate, for . Note that a rate of 5% should be entered as 0.05.
8: – Real (Kind=nag_wp) arrayOutput
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.
Constraint:
, or .
10: – Integer arrayOutput
On exit: 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 Section 9 for further details.
11: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or is used it is essential to test the value of ifail on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry at least one input argument was invalid. Check ivalid for more information.
On entry, .
Constraint: .
On entry, . Constraint: , or .
On entry, was an illegal value.
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL 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 FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
If or then s30acf 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
s30acf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
When or , s30acf uses an algorithm optimized for performance on large vectors of input data () by exploiting vector instructions when available.
When , s30acf 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.
9Further Comments
The domain of inputs, , , , and , for which s30acf is able to accurately compute is very large and should cover all practical applications of this routine. 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 . s30acf should then be called with , and in place of , and respectively.
s30acf 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 routine.
10Example
This example reads in values of , , , and from a file, evaluates the implied volatilities, , and prints the results.