code: def test_calibration(
      self,
      true_mean_reversion,
      true_initial_variance,
      true_theta,
      true_volvol,
      true_rho,
      max_iterations,
      tolerance,
      noise_size,
      price_tol,
  ):
      dtype = np.float64
  
      # Construct some market conditions.
      strikes = np.array(
          [
              [80.0, 90.0, 100.0, 110.0, 120.0],
              [80.0, 90.0, 100.0, 110.0, 120.0],
          ],
          dtype=dtype,
      )
      expiries = np.array([[0.5], [1.0]], dtype=dtype)
      is_call_options = np.array([[True], [False]])
      forwards = 100.0
  
      # Generate some prices.
      denoised_prices = (
          tff.models.heston.approximations.european_option_price(
              forwards=forwards,
              strikes=strikes,
              expiries=expiries,
              is_call_options=is_call_options,
              mean_reversion=np.expand_dims(
                  true_mean_reversion, axis=-1
              ),
              variances=np.expand_dims(true_initial_variance, axis=-1),
              theta=np.expand_dims(true_theta, axis=-1),
              volvol=np.expand_dims(true_volvol, axis=-1),
              rho=np.expand_dims(true_rho, axis=-1),
              dtype=dtype,
          )
      )
  
      # Add noise to the prices
      observed_prices = denoised_prices + tf.random.stateless_normal(
          denoised_prices.shape,
          stddev=noise_size * denoised_prices,
          seed=[2, 4],
          dtype=dtype,
      )
  
      # Calibrate the models.
      models, _, _ = tff.models.heston.calibration(
          prices=observed_prices,
          strikes=strikes,
          expiries=expiries,
          forwards=forwards,
          is_call_options=is_call_options,
          mean_reversion=np.array([0.4, 0.4], dtype=dtype),
          initial_variance=np.array([0.25, 0.25], dtype=dtype),
          theta=np.array([0.9, 0.9], dtype=dtype),
          volvol=np.array([0.75, 0.75], dtype=dtype),
          rho=np.array([-0.5, -0.5], dtype=dtype),
          maximum_iterations=max_iterations,
          tolerance=tolerance,
          dtype=dtype,
      )
  
      [
          calibrated_initial_variance,
          calibrated_mean_reversion,
          calibrated_volvol,
          calibrated_rho,
          calibrated_theta,
      ] = self.evaluate(
          [
              models.initial_variance,
              models.mean_reversion,
              models.volvol,
              models.rho,
              models.theta,
          ]
      )
  
      # Back out the approximated prices from the calibrated model, and check that
      # they agree with our input prices (up to noise)
      calibrated_prices = (
          tff.models.heston.approximations.european_option_price(
              forwards=forwards,
              strikes=strikes,
              expiries=expiries,
              is_call_options=is_call_options,
              variances=np.array(
                  np.expand_dims(calibrated_initial_variance, axis=1),
                  dtype=dtype,
              ),
              mean_reversion=np.array(
                  np.expand_dims(calibrated_mean_reversion, axis=1),
                  dtype=dtype,
              ),
              theta=np.array(
                  np.expand_dims(calibrated_theta, axis=1), dtype=dtype
              ),
              volvol=np.array(
                  np.expand_dims(calibrated_volvol, axis=1), dtype=dtype
              ),
              rho=np.array(
                  np.expand_dims(calibrated_rho, axis=1), dtype=dtype
              ),
              dtype=dtype,
          )
      )
  
      calibrated_prices, denoised_prices = self.evaluate(
          [calibrated_prices, denoised_prices]
      )
      with self.subTest("noiseScenarios"):
          self.assertAllClose(
              calibrated_prices,
              denoised_prices,
              atol=price_tol[0],
              rtol=price_tol[1],
          )
  
file_path: tf-quant-finance/tf_quant_finance/models/heston/approximations/calibration_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 5 for calling the CalibrationTest obj's underlying member method code with example usage: obj.test_calibration(true_mean_reversion, true_initial_variance, true_theta, true_volvol, true_rho, max_iterations, tolerance, noise_size, price_tol) without return types