docstr: Tests calibration with constant parameters.
docstr_tok: ["Tests","calibration","with","constant","parameters","."]
code: def test_correctness(
      self,
      optimizer_fn,
      noise_size,
      use_analytic_pricing,
      expected_mr,
      expected_vol,
      mr_rtol=1e-4,
      mr_atol=1e-3,
      vol_rtol=1e-4,
      vol_atol=1e-3,
  ):
      """Tests calibration with constant parameters."""
      dtype = tf.float64
  
      # Setup - generate some observed prices using the model.
      zero_rate_fn = lambda x: 0.01 * tf.ones_like(x)
      prices = tff.models.hull_white.cap_floor_price(
          strikes=self.strikes,
          expiries=self.expiries,
          maturities=self.maturities,
          daycount_fractions=self.daycount_fractions,
          reference_rate_fn=zero_rate_fn,
          notional=1.0,
          mean_reversion=[expected_mr],
          volatility=[expected_vol],
          is_cap=tf.expand_dims(self.is_cap, axis=1),
          use_analytic_pricing=True,
          dtype=dtype,
      )
  
      prices = prices + tf.random.normal(
          prices.shape, stddev=noise_size * prices, seed=0, dtype=dtype
      )
  
      # Calibrate the model.
      (
          calibrated_model,
          is_converged,
          _,
      ) = tff.models.hull_white.calibration_from_cap_floors(
          prices=prices,
          strikes=self.strikes,
          expiries=self.expiries,
          maturities=self.maturities,
          daycount_fractions=self.daycount_fractions,
          reference_rate_fn=zero_rate_fn,
          mean_reversion=[0.4],
          volatility=[0.02],
          notional=1.0,
          is_cap=tf.expand_dims(self.is_cap, axis=1),
          use_analytic_pricing=use_analytic_pricing,
          optimizer_fn=optimizer_fn,
          num_samples=1000,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[0, 0],
          time_step=0.1,
          maximum_iterations=200,
          dtype=dtype,
      )
  
      calib_parameters = tf.concat(
          axis=0,
          values=[
              calibrated_model.mean_reversion.values(),
              calibrated_model.volatility.values(),
          ],
      )
      calib_parameters = self.evaluate(calib_parameters)
      mr = calib_parameters[0]
      vol = calib_parameters[1]
  
      # Assert model convergence to expected parameters.
      self.assertTrue(is_converged)
      self.assertAllClose(mr, expected_mr, rtol=mr_rtol, atol=mr_atol)
      self.assertAllClose(
          vol, expected_vol, rtol=vol_rtol, atol=vol_atol
      )
  
file_path: tf-quant-finance/tf_quant_finance/models/hull_white/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 3 for calling the HullWhiteCalibrationCapFloorTest obj's underlying member method code with example usage: obj.test_correctness(optimizer_fn, noise_size, use_analytic_pricing, expected_mr, expected_vol, mr_rtol, mr_atol, vol_rtol, vol_atol) without return types