code: def _make_bachelier_objective_and_vega_func(
      prices,
      forwards,
      strikes,
      expiries,
      is_call_options,
      discount_factors,
  ):
      """Produces an objective and vega function for the Bachelier model.
  
      The returned function maps volatilities to a tuple of objective function
      values and their gradients with respect to the volatilities. The objective
      function is the difference between model implied prices and observed market
      prices, whereas the gradient is called vega of the option. That is:
  
      ```
      g(s) = (f(s) - a, f'(s))
      ```
  
      Where `g` is the returned function taking volatility parameter `s`, `f` the
      Black Scholes price with all other variables curried and `f'` its derivative,
      and `a` the observed market prices of the options. Hence `g` calculates the
      information necessary for finding the volatility implied by observed market
      prices for options with given terms using first order methods.
  
      #### References
      [1] Wenqing H., 2013. Risk Measures with Normal Distributed Black Options
      Pricing Model. Mälardalen University, Sweden. (p. 10 - 17)
  
      Args:
        prices: A real `Tensor` of any shape. The observed market prices of the
          options.
        forwards: A real `Tensor` of the same shape and dtype as `prices`. The
          current forward prices to expiry.
        strikes: A real `Tensor` of the same shape and dtype as `prices`. The strike
          prices of the options.
        expiries: A real `Tensor` of same shape and dtype as `forwards`. The expiry
          for each option. The units should be such that `expiry * volatility**2` is
          dimensionless.
        is_call_options: A boolean `Tensor` of same shape and dtype as `forwards`.
          `True` for call options and `False` for put options.
        discount_factors: A real `Tensor` of the same shape and dtype as `forwards`.
          The total discount factors to option expiry.
  
      Returns:
        A function from volatilities to a Black Scholes objective and its
        derivative (which is coincident with Vega).
      """
      (
          normalized_prices,
          normalization,
          discount_factors,
      ) = _get_normalizations(
          prices, forwards, strikes, discount_factors
      )
      norm_forwards = forwards / normalization
      norm_strikes = strikes / normalization
      sqrt_t = tf.sqrt(expiries)
      if is_call_options is not None:
          is_call_options = tf.convert_to_tensor(
              is_call_options, dtype=tf.bool, name="is_call_options"
          )
  
      def _objective_and_vega(volatilities):
          """Calculate the Bachelier price and vega for a given volatility.
  
          This method returns normalized results.
  
          Args:
            volatilities: A real `Tensor` of same shape and dtype as `forwards`. The
              volatility to expiry.
  
          Returns:
            A tuple containing (value, gradient) of the black scholes price, both of
              which are `Tensor`s of the same shape and dtype as `volatilities`.
          """
          vols = volatilities * sqrt_t / normalization
          d1 = (norm_forwards - norm_strikes) / vols
          implied_prices = (norm_forwards - norm_strikes) * _cdf(
              d1
          ) + vols * _pdf(d1)
          if is_call_options is not None:
              put_prices = implied_prices - norm_forwards + norm_strikes
              implied_prices = tf.where(
                  is_call_options, implied_prices, put_prices
              )
  
          vega = _pdf(d1) * sqrt_t / discount_factors / normalization
          return implied_prices - normalized_prices, vega
  
      return _objective_and_vega
  
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 7 for calling a global function with example usage: _make_bachelier_objective_and_vega_func(prices, forwards, strikes, expiries, is_call_options, discount_factors) and returns: _objective_and_vega, unknown,  vega