code: def _newton_implied_vol(
      prices,
      strikes,
      expiries,
      forwards,
      discount_factors,
      is_call_options,
      initial_volatilities,
      underlying_distribution,
      tolerance,
      max_iterations,
  ):
      """Uses Newton's method to find Black Scholes implied volatilities of options.
  
      Finds the volatility implied under the Black Scholes option pricing scheme for
      a set of European options given observed market prices. The implied volatility
      is found via application of Newton's algorithm for locating the root of a
      differentiable function.
  
      The implementation assumes that each cell in the supplied tensors corresponds
      to an independent volatility to find.
  
      Args:
        prices: A real `Tensor` of any shape. The prices of the options whose
          implied vol is to be calculated.
        strikes: A real `Tensor` of the same dtype as `prices` and a shape that
          broadcasts with `prices`. The strikes of the options.
        expiries: A real `Tensor` of the same dtype as `prices` and a shape that
          broadcasts with `prices`. The expiry for each option. The units should be
          such that `expiry * volatility**2` is dimensionless.
        forwards: A real `Tensor` of any shape that broadcasts to the shape of
          `prices`. The forwards to maturity.
        discount_factors: An optional real `Tensor` of same dtype as the `prices`.
          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 ).
        is_call_options: A boolean `Tensor` of a shape compatible with `prices`.
          Indicates whether the option is a call (if True) or a put (if False). If
          not supplied, call options are assumed.
        initial_volatilities: A real `Tensor` of the same shape and dtype as
          `forwards`. The starting positions for Newton's method.
        underlying_distribution: Enum value of ImpliedVolUnderlyingDistribution to
          select the distribution of the underlying.
        tolerance: `float`. The root finder will stop where this tolerance is
          crossed.
        max_iterations: `int`. The maximum number of iterations of Newton's method.
  
      Returns:
        A three tuple of `Tensor`s, each the same shape as `forwards`. It
        contains the implied volatilities (same dtype as `forwards`), a boolean
        `Tensor` indicating whether the corresponding implied volatility converged,
        and a boolean `Tensor` which is true where the corresponding implied
        volatility is not a finite real number.
      """
      if (
          underlying_distribution
          is utils.UnderlyingDistribution.LOG_NORMAL
      ):
          pricer = _make_black_lognormal_objective_and_vega_func(
              prices,
              forwards,
              strikes,
              expiries,
              is_call_options,
              discount_factors,
          )
      elif (
          underlying_distribution is utils.UnderlyingDistribution.NORMAL
      ):
          pricer = _make_bachelier_objective_and_vega_func(
              prices,
              forwards,
              strikes,
              expiries,
              is_call_options,
              discount_factors,
          )
  
      results = newton.root_finder(
          pricer,
          initial_volatilities,
          max_iterations=max_iterations,
          tolerance=tolerance,
      )
      return results
  
file_path: tf-quant-finance/tf_quant_finance/black_scholes/implied_vol_newton_root.py
imports: import numpy
  import tensorflow.compat.v2
  from tf_quant_finance.black_scholes import implied_vol_approximation
  from tf_quant_finance.black_scholes import implied_vol_utils
  from tf_quant_finance.math.root_search import newton
label_desc: Use image node_id 4 for calling a global function with example usage: _newton_implied_vol(prices, strikes, expiries, forwards, discount_factors, is_call_options, initial_volatilities, underlying_distribution, tolerance, max_iterations) and returns: results