code: def test_validate_args(self):
      dtype = np.float64
  
      observed_prices = np.array(
          [
              [
                  29.45783648,
                  24.15306768,
                  19.73346361,
                  16.08792179,
                  13.10198113,
              ],
              [
                  16.02509124,
                  21.51061818,
                  27.61195796,
                  34.24527161,
                  41.33562669,
              ],
          ],
          dtype=dtype,
      )
  
      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)
      forwards = 100.0
      is_call_options = np.array([[True], [False]])
  
      initial_variance = np.array([0.5], dtype=dtype)
      mean_reversion = np.array([0.25], dtype=dtype)
      theta = np.array([0.5], dtype=dtype)
  
      # Fails because `volvol` is outside the limits.
      with self.subTest("volvolInvalidArgumentCaught"):
          with self.assertRaises(tf.errors.InvalidArgumentError):
              _, is_converged, _ = tff.models.heston.calibration(
                  prices=observed_prices,
                  strikes=strikes,
                  expiries=expiries,
                  forwards=forwards,
                  is_call_options=is_call_options,
                  mean_reversion=mean_reversion,
                  initial_variance=initial_variance,
                  theta=theta,
                  volvol=np.array([10.5], dtype=dtype),
                  volvol_lower_bound=0.0,
                  volvol_upper_bound=10.0,
                  rho=np.array([0.0], dtype=dtype),
                  rho_lower_bound=-0.75,
                  rho_upper_bound=0.75,
                  validate_args=True,
              )
              self.evaluate(is_converged)
  
      # Fails because `rho` exceeds its expected bounds.
      with self.subTest("rhoInvalidArgumentCaught"):
          with self.assertRaises(tf.errors.InvalidArgumentError):
              _, is_converged, _ = tff.models.heston.calibration(
                  prices=observed_prices,
                  strikes=strikes,
                  expiries=expiries,
                  forwards=forwards,
                  is_call_options=is_call_options,
                  mean_reversion=mean_reversion,
                  initial_variance=initial_variance,
                  theta=theta,
                  volvol=np.array([0.5], dtype=dtype),
                  volvol_lower_bound=0.0,
                  volvol_upper_bound=10.0,
                  rho=np.array([0.76], dtype=dtype),
                  rho_lower_bound=-0.75,
                  rho_upper_bound=0.75,
                  validate_args=True,
              )
              self.evaluate(is_converged)
  
      # Arguments are okay.
      _, is_converged, _ = tff.models.heston.calibration(
          prices=observed_prices,
          strikes=strikes,
          expiries=expiries,
          forwards=forwards,
          is_call_options=is_call_options,
          mean_reversion=mean_reversion,
          initial_variance=initial_variance,
          theta=theta,
          volvol=np.array([0.5], 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,
          validate_args=True,
      )
      is_converged = self.evaluate(is_converged)
      with self.subTest("allArgumentsWithinBounds"):
          self.assertTrue(all(is_converged))
  
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 4 for calling the CalibrationTest obj's underlying member method code with example usage: obj.test_validate_args() without return types