docstr: Tests finite difference valuation for a batch with 3 factor HJM.
docstr_tok: ["Tests","finite","difference","valuation","for","a","batch","with","3","factor","HJM","."]
code: def test_correctness_3_factor_batch_fd(self):
      """Tests finite difference valuation for a batch with 3 factor HJM."""
      # 1y x 1y swaption with quarterly payments.
      dtype = tf.float64
      error_tol = 1e-3
  
      expiries = np.array([1.002739726, 1.002739726])
      fixed_leg_payment_times = np.array(
          [
              [1.249315068, 1.498630137, 1.750684932, 2.002739726],
              [1.249315068, 1.498630137, 1.750684932, 2.002739726],
          ]
      )
      fixed_leg_daycount_fractions = np.array(
          [
              [0.2465753425, 0.2493150685, 0.2520547945, 0.2520547945],
              [0.2465753425, 0.2493150685, 0.2520547945, 0.2520547945],
          ]
      )
      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)
  
      mean_reversion = [0.03, 0.15, 0.25]
      volatility = [0.01, 0.015, 0.009]
  
      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=3,
          mean_reversion=mean_reversion,
          volatility=volatility,
          valuation_method=tff.models.ValuationMethod.FINITE_DIFFERENCE,
          time_step_finite_difference=0.05,
          num_grid_points_finite_difference=51,
          time_step=0.1,
          dtype=dtype,
      )
  
      very_approximate_benchmark = 0.56020399
      self.assertEqual(price.dtype, dtype)
      self.assertAllEqual(price.shape, [2])
      price = self.evaluate(price)
      self.assertAllClose(
          price,
          [very_approximate_benchmark, very_approximate_benchmark],
          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 12 for calling the HJMSwaptionTest obj's underlying member method code with example usage: obj.test_correctness_3_factor_batch_fd() without return types