Last updated: 2023-03-16.
tf_quant_finance.black_scholes.implied_vol_newton#
Computes implied volatilities from given call or put option prices.
tf_quant_finance.black_scholes.implied_vol_newton(
*, prices, strikes, expiries, spots=None, forwards=None, discount_factors=None,
is_call_options=None, initial_volatilities=None, underlying_distribution=tf_quan
t_finance.black_scholes.ImpliedVolUnderlyingDistribution.LOG_NORMAL,
tolerance=1e-08, max_iterations=20, validate_args=False, dtype=None, name=None
)
This method applies a Newton root search algorithm to back out the implied volatility given the price of either a put or a call option.
The implementation assumes that each cell in the supplied tensors corresponds to an independent volatility to find.
Args:#
prices: A realTensorof any shape. The prices of the options whose implied vol is to be calculated.strikes: A realTensorof the same dtype aspricesand a shape that broadcasts withprices. The strikes of the options.expiries: A realTensorof the same dtype aspricesand a shape that broadcasts withprices. The expiry for each option. The units should be such thatexpiry * volatility**2is dimensionless.spots: A realTensorof any shape that broadcasts to the shape of theprices. The current spot price of the underlying. Either this argument or theforwards(but not both) must be supplied. Default value: None.forwards: A realTensorof any shape that broadcasts to the shape ofprices. The forwards to maturity. Either this argument or thespotsmust be supplied but both must not be supplied. Default value: None.discount_factors: An optional realTensorof same dtype as theprices. If not None, these are the discount factors to expiry (i.e. e^(-rT)). If None, no discounting is applied (i.e. it is assumed that the undiscounted option prices are provided ). Ifspotsis supplied anddiscount_factorsis not None then this is also used to compute the forwards to expiry. Default value: None, equivalent to discount factors = 1.is_call_options: A booleanTensorof a shape compatible withprices. Indicates whether the option is a call (if True) or a put (if False). If not supplied, call options are assumed. Default value: None.initial_volatilities: A realTensorof the same shape and dtype asforwards. The starting positions for Newton’s method. Default value: None. If not supplied, the starting point is chosen using the Stefanica-Radoicic scheme. Seepolya_approx.implied_volfor details. Default value: None.underlying_distribution: Enum value of ImpliedVolUnderlyingDistribution to select the distribution of the underlying. Default value: UnderlyingDistribution.LOG_NORMALtolerance:float. The root finder will stop where this tolerance is crossed.max_iterations:int. The maximum number of iterations of Newton’s method. Default value: 20.validate_args: A Python bool. If True, indicates that arguments should be checked for correctness before performing the computation. The checks performed are: (1) Forwards and strikes are positive. (2) The prices satisfy the arbitrage bounds (i.e. for call options, checks the inequalitymax(F-K, 0) <= Price <= Fand for put options, checks thatmax(K-F, 0) <= Price <= K.). (3) Checks that the prices are not too close to the bounds. It is numerically unstable to compute the implied vols from options too far in the money or out of the money. Default value: False.dtype:tf.Dtypeto use when converting arguments toTensors. If not supplied, the default TensorFlow conversion will take place. Note that this argument does not do any casting forTensors or numpy arrays. Default value: None.name: (Optional) Python str. The name prefixed to the ops created by this function. If not supplied, the default name ‘implied_vol’ is used. Default value: None.
Returns:#
A 3-tuple containing the following items in order:
(a) implied_vols: A Tensor of the same dtype as prices and shape as
the common broadcasted shape of
(prices, spots/forwards, strikes, expiries). The implied vols as
inferred by the algorithm. It is possible that the search may not have
converged or may have produced NaNs. This can be checked for using the
following return values.
(b) converged: A boolean Tensor of the same shape as implied_vols
above. Indicates whether the corresponding vol has converged to within
tolerance.
(c) failed: A boolean Tensor of the same shape as implied_vols above.
Indicates whether the corresponding vol is NaN or not a finite number.
Note that converged being True implies that failed will be false.
However, it may happen that converged is False but failed is not True.
This indicates the search did not converge in the permitted number of
iterations but may converge if the iterations are increased.
Raises:#
ValueError: If bothforwardsandspotsare supplied or if neither is supplied.