code: def test_calibration(
      self,
      true_alpha,
      true_beta,
      true_volvol,
      true_rho,
      calibrate_beta,
      vol_based_calibration,
      max_iterations,
      tolerance,
      vol_type,
      noise_size,
      price_tol,
  ):
      dtype = np.float64
  
      # Construct some market conditions.
      strikes = np.array(
          [np.arange(95, 105.10, 0.1), np.arange(95, 105.10, 0.1)],
          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.sabr.approximations.european_option_price(
              forwards=forwards,
              strikes=strikes,
              expiries=expiries,
              is_call_options=is_call_options,
              alpha=np.expand_dims(true_alpha, axis=-1),
              beta=np.expand_dims(true_beta, axis=-1),
              volvol=np.expand_dims(true_volvol, axis=-1),
              rho=np.expand_dims(true_rho, axis=-1),
              volatility_type=vol_type,
              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.
      initial_beta = (
          np.array([0.5, 0.5], dtype=dtype)
          if calibrate_beta
          else true_beta
      )
      models, _, _ = tff.models.sabr.calibration(
          prices=observed_prices,
          strikes=strikes,
          expiries=expiries,
          forwards=forwards,
          is_call_options=is_call_options,
          beta=initial_beta,
          calibrate_beta=calibrate_beta,
          volatility_based_calibration=vol_based_calibration,
          volvol=np.array([1.0, 1.0], dtype=dtype),
          volvol_lower_bound=0.0,
          volvol_upper_bound=10.0,
          rho=np.array([0.0, 0.0], dtype=dtype),
          rho_lower_bound=-0.75,
          rho_upper_bound=0.75,
          volatility_type=vol_type,
          maximum_iterations=max_iterations,
          tolerance=tolerance,
          dtype=dtype,
      )
  
      (
          calibrated_alpha,
          calibrated_beta,
          calibrated_volvol,
          calibrated_rho,
      ) = self.evaluate(
          [models.alpha, models.beta, models.volvol, models.rho]
      )
  
      # 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.sabr.approximations.european_option_price(
              forwards=forwards,
              strikes=strikes,
              expiries=expiries,
              is_call_options=is_call_options,
              alpha=np.array(
                  np.expand_dims(calibrated_alpha, axis=1), dtype=dtype
              ),
              beta=np.array(
                  np.expand_dims(calibrated_beta, 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
              ),
              volatility_type=vol_type,
              dtype=dtype,
          )
      )
  
      calibrated_prices, denoised_prices = self.evaluate(
          [calibrated_prices, denoised_prices]
      )
      self.assertAllClose(
          calibrated_prices,
          denoised_prices,
          atol=price_tol[0],
          rtol=price_tol[1],
      )
  
file_path: tf-quant-finance/tf_quant_finance/models/sabr/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_alpha, true_beta, true_volvol, true_rho, calibrate_beta, vol_based_calibration, max_iterations, tolerance, vol_type, noise_size, price_tol) without return types