docstr: Test that under certain conditions HJM matches analytic HW results.
  
  Args:
    valuation_method: The valuation method used.
    error_tol: Test error tolerance.
  
  For the two factor model, when both mean reversions are equivalent, then
  the HJM model matches that of a HW one-factor model with the same mean
  reversion, and effective volatility:
  eff_vol = sqrt(vol1^2 + vol2^2 + 2 rho(vol1 * vol2)
  where rho is the cross correlation between the two factors. In this
  specific test, we assume rho = 0.0.
docstr_tok: ["Test","that","under","certain","conditions","HJM","matches","analytic","HW","results",".","Args",":","valuation_method",":","The","valuation","method","used",".","error_tol",":","Test","error","tolerance",".","For","the","two","factor","model",",","when","both","mean","reversions","are","equivalent",",","then","the","HJM","model","matches","that","of","a","HW","one-factor","model","with","the","same","mean","reversion",",","and","effective","volatility",":","eff_vol","=","sqrt","(","vol1^2","+","vol2^2","+","2","rho","(","vol1","*","vol2",")","where","rho","is","the","cross","correlation","between","the","two","factors",".","In","this","specific","test",",","we","assume","rho","=","0.0","."]
code: def test_correctness_2_factor_hull_white_consistency(
      self, valuation_method, error_tol
  ):
      """Test that under certain conditions HJM matches analytic HW results.
  
      Args:
        valuation_method: The valuation method used.
        error_tol: Test error tolerance.
  
      For the two factor model, when both mean reversions are equivalent, then
      the HJM model matches that of a HW one-factor model with the same mean
      reversion, and effective volatility:
      eff_vol = sqrt(vol1^2 + vol2^2 + 2 rho(vol1 * vol2)
      where rho is the cross correlation between the two factors. In this
      specific test, we assume rho = 0.0.
      """
      dtype = tf.float64
  
      expiries = np.array([1.0])
      fixed_leg_payment_times = np.array([1.25, 1.5, 1.75, 2.0])
      fixed_leg_daycount_fractions = 0.25 * np.ones_like(
          fixed_leg_payment_times
      )
      fixed_leg_coupon = 0.011 * np.ones_like(fixed_leg_payment_times)
      zero_rate_fn = lambda x: 0.01 * tf.ones_like(x, dtype=dtype)
  
      mu = 0.03
      vol1 = 0.02
      vol2 = 0.01
      eff_vol = np.sqrt(vol1**2 + vol2**2)
  
      hjm_price = tff.models.hjm.swaption_price(
          expiries=expiries,
          fixed_leg_payment_times=fixed_leg_payment_times,
          fixed_leg_daycount_fractions=fixed_leg_daycount_fractions,
          fixed_leg_coupon=fixed_leg_coupon,
          reference_rate_fn=zero_rate_fn,
          notional=100.0,
          num_hjm_factors=2,
          mean_reversion=[mu, mu],
          volatility=[vol1, vol2],
          num_samples=25_000,
          valuation_method=valuation_method,
          time_step_finite_difference=0.05,
          num_grid_points_finite_difference=251,
          time_step=0.1,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[1, 2],
          dtype=dtype,
      )
      hjm_price = self.evaluate(hjm_price)
  
      hw_price = tff.models.hull_white.swaption_price(
          expiries=expiries,
          floating_leg_start_times=[0],  # Unused
          floating_leg_end_times=[0],  # Unused
          floating_leg_daycount_fractions=[0],  # Unused
          fixed_leg_payment_times=fixed_leg_payment_times,
          fixed_leg_daycount_fractions=fixed_leg_daycount_fractions,
          fixed_leg_coupon=fixed_leg_coupon,
          reference_rate_fn=zero_rate_fn,
          notional=100.0,
          mean_reversion=[mu],
          volatility=[eff_vol],
          use_analytic_pricing=True,
          dtype=dtype,
      )
      hw_price = self.evaluate(hw_price)
  
      self.assertNear(hjm_price, hw_price, error_tol)
  
file_path: tf-quant-finance/tf_quant_finance/models/hjm/swaption_pricing_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 8 for calling the HJMSwaptionTest obj's underlying member method code with example usage: obj.test_correctness_2_factor_hull_white_consistency(valuation_method, error_tol) without return types