docstr: Tests calibration with constant parameters.
docstr_tok: ["Tests","calibration","with","constant","parameters","."]
code: def test_calibration(
      self,
      optimizer_fn,
      vol_based_calib,
      num_hjm_factors,
      time_step,
      num_time_steps,
      num_instruments,
      max_iter,
  ):
      """Tests calibration with constant parameters."""
      dtype = tf.float64
      mr0 = [0.01, 0.05]
      if num_hjm_factors == 3:
          mr0 = [0.01, 0.05, 0.1]
  
      vol0 = [0.005, 0.007]
      if num_hjm_factors == 3:
          vol0 = [0.002, 0.003, 0.008]
  
      zero_rate_fn = lambda x: 0.01 * tf.ones_like(x, dtype=dtype)
  
      times = np.unique(
          np.reshape(self.expiries[:num_instruments], [-1])
      )
      curve_times = None
      random_type = tff.math.random.RandomType.STATELESS_ANTITHETIC
      seed = [0, 0]
      num_samples = 500
  
      valuation_method = tff.models.ValuationMethod.MONTE_CARLO
  
      def _fn():
          (
              (calib_mr, calib_vol, calib_corr),
              _,
              _,
          ) = tff.models.hjm.calibration_from_swaptions(
              prices=self.prices[:num_instruments],
              expiries=self.expiries[:num_instruments],
              floating_leg_start_times=self.float_leg_start_times[
                  :num_instruments, :
              ],
              floating_leg_end_times=self.float_leg_end_times[
                  :num_instruments, :
              ],
              fixed_leg_payment_times=self.fixed_leg_payment_times[
                  :num_instruments, :
              ],
              floating_leg_daycount_fractions=self.float_leg_daycount_fractions[
                  :num_instruments, :
              ],
              fixed_leg_daycount_fractions=self.fixed_leg_daycount_fractions[
                  :num_instruments, :
              ],
              fixed_leg_coupon=self.fixed_leg_coupon[
                  :num_instruments, :
              ],
              reference_rate_fn=zero_rate_fn,
              notional=100.0,
              num_hjm_factors=num_hjm_factors,
              mean_reversion=mr0,
              volatility=vol0,
              optimizer_fn=optimizer_fn,
              volatility_based_calibration=vol_based_calib,
              swaption_valuation_method=valuation_method,
              num_samples=num_samples,
              random_type=random_type,
              seed=seed,
              time_step=time_step,
              num_time_steps=num_time_steps,
              times=times,
              curve_times=curve_times,
              time_step_finite_difference=time_step,
              num_grid_points_finite_difference=41,
              maximum_iterations=max_iter,
              dtype=dtype,
          )
          return calib_mr, calib_vol, calib_corr
  
      calib_mr, calib_vol, calib_corr = self.evaluate(_fn())
  
      prices = tff.models.hjm.swaption_price(
          expiries=self.expiries[:num_instruments],
          fixed_leg_payment_times=self.fixed_leg_payment_times[
              :num_instruments, :
          ],
          fixed_leg_daycount_fractions=self.fixed_leg_daycount_fractions[
              :num_instruments, :
          ],
          fixed_leg_coupon=self.fixed_leg_coupon[:num_instruments, :],
          reference_rate_fn=zero_rate_fn,
          num_hjm_factors=num_hjm_factors,
          notional=100.0,
          mean_reversion=calib_mr,
          volatility=calib_vol,
          corr_matrix=calib_corr,
          num_samples=num_samples,
          random_type=random_type,
          seed=seed,
          time_step=time_step,
          num_time_steps=num_time_steps,
          times=times,
          curve_times=curve_times,
          time_step_finite_difference=time_step,
          num_grid_points_finite_difference=101,
          valuation_method=valuation_method,
          dtype=dtype,
      )
  
      prices = self.evaluate(prices)
      self.assertAllClose(
          prices, self.prices[:num_instruments], rtol=0.1, atol=0.1
      )
  
file_path: tf-quant-finance/tf_quant_finance/models/hjm/calibration_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tensorflow_probability
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 2 for calling the HJMCalibrationTest obj's underlying member method code with example usage: obj.test_calibration(optimizer_fn, vol_based_calib, num_hjm_factors, time_step, num_time_steps, num_instruments, max_iter) and returns: calib_mr,  calib_vol,  calib_corr