code: def _analytic_valuation(
      expiries,
      floating_leg_start_times,
      floating_leg_end_times,
      fixed_leg_payment_times,
      fixed_leg_daycount_fractions,
      fixed_leg_coupon,
      reference_rate_fn,
      mean_reversion,
      volatility,
      notional,
      is_payer_swaption,
      dtype,
      name,
  ):
      """Helper function for analytic valuation."""
      # The below inputs are needed for midcurve swaptions
      del floating_leg_start_times, floating_leg_end_times
      with tf.name_scope(name):
          is_call_options = tf.where(
              is_payer_swaption,
              tf.convert_to_tensor(False, dtype=tf.bool),
              tf.convert_to_tensor(True, dtype=tf.bool),
          )
  
          model = one_factor.HullWhiteModel1F(
              mean_reversion,
              volatility,
              initial_discount_rate_fn=reference_rate_fn,
              dtype=dtype,
          )
          coefficients = fixed_leg_daycount_fractions * fixed_leg_coupon
          # Shape `batch_shape + [num_payments]`
          jamshidian_coefficients = tf.concat(
              [
                  -coefficients[..., :-1],
                  tf.expand_dims(-1.0 - coefficients[..., -1], axis=-1),
              ],
              axis=-1,
          )
          # Shape `batch_shape`
          breakeven_bond_option_strikes = _jamshidian_decomposition(
              model,
              expiries,
              fixed_leg_payment_times,
              jamshidian_coefficients,
              dtype,
              name=name + "_jamshidian_decomposition",
          )[..., 0]
          bond_option_prices = zcb.bond_option_price(
              strikes=breakeven_bond_option_strikes,
              expiries=expiries,
              maturities=fixed_leg_payment_times,
              discount_rate_fn=reference_rate_fn,
              mean_reversion=mean_reversion,
              volatility=volatility,
              is_call_options=is_call_options,
              use_analytic_pricing=True,
              dtype=dtype,
              name=name + "_bond_option",
          )
  
          # Now compute P(T0, TN) + sum_i (c_i * tau_i * P(T0, Ti))
          # bond_option_prices.shape = batch_shape + [m], where `m`
          # denotes the number of fixed payments for the underlying swaps.
          # Shape `batch_shape`
          swaption_values = (
              tf.reduce_sum(bond_option_prices * coefficients, axis=-1)
              + bond_option_prices[..., -1]
          )
          return notional * swaption_values
  
imports: from typing import Callable, Union
  import numpy
  import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance.math import pde
  from tf_quant_finance.math import random
  from tf_quant_finance.math.interpolation import linear
  from tf_quant_finance.math.root_search import brent
  from tf_quant_finance.models import utils
  from tf_quant_finance.models.hjm import swaption_util
  from tf_quant_finance.models.hull_white import one_factor
  from tf_quant_finance.models.hull_white import zero_coupon_bond_option
  from tf_quant_finance.models.longstaff_schwartz import lsm
label_desc: Use image node_id 8 for calling a global function with example usage: _analytic_valuation(expiries, floating_leg_start_times, floating_leg_end_times, fixed_leg_payment_times, fixed_leg_daycount_fractions, fixed_leg_coupon, reference_rate_fn, mean_reversion, volatility, notional, is_payer_swaption, dtype, name) and returns: unknown