docstr: Tests model with constant parameters in 2 dimensions.
docstr_tok: ["Tests","model","with","constant","parameters","in","2","dimensions","."]
code: def test_correctness_2_factor(self):
      """Tests model with constant parameters in 2 dimensions."""
      # 1y x 1y swaption with quarterly payments.
      dtype = tf.float64
      error_tol = 1e-2
  
      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)
      mean_reversion = [0.03, 0.06]
      volatility = [0.02, 0.01]
      zero_rate_fn = lambda x: 0.01 * tf.ones_like(x, dtype=dtype)
  
      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=mean_reversion,
          volatility=volatility,
          num_samples=25_000,
          time_step=0.1,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[1, 2],
          dtype=dtype,
      )
  
      self.assertEqual(price.dtype, dtype)
      self.assertAllEqual(price.shape, [1])
      price = self.evaluate(price)
      self.assertAllClose(
          price, [0.802226], rtol=error_tol, atol=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 7 for calling the HJMSwaptionTest obj's underlying member method code with example usage: obj.test_correctness_2_factor() without return types