docstr: Test calibration function with dynamically shaped inputs.
docstr_tok: ["Test","calibration","function","with","dynamically","shaped","inputs","."]
code: def test_dynamic_shapes(self):
      """Test calibration function with dynamically shaped inputs."""
      dtype = np.float64
  
      observed_prices = np.array(
          [
              [
                  20.09689284,
                  10.91953054,
                  4.25012702,
                  1.11561839,
                  0.20815853,
              ],
              [
                  3.34813209,
                  6.03578711,
                  10.2874194,
                  16.26824328,
                  23.73850935,
              ],
          ],
          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], [100.0]]
      is_call_options = np.array([[True], [False]])
  
      beta = np.array([0.5], dtype=dtype)
      volvol = np.array([1.0], dtype=dtype)
  
      @tf.function(
          input_signature=[
              tf.TensorSpec([None, None], dtype=dtype),
              tf.TensorSpec([None, None], dtype=dtype),
              tf.TensorSpec([None, None], dtype=dtype),
              tf.TensorSpec([None, None], dtype=dtype),
              tf.TensorSpec([None, None], dtype=tf.bool),
              tf.TensorSpec([None], dtype=dtype),
              tf.TensorSpec([None], dtype=dtype),
          ]
      )
      def fn(
          observed_prices,
          strikes,
          expiries,
          forwards,
          is_call_options,
          beta,
          volvol,
      ):
          models, is_converged, _ = tff.models.sabr.calibration(
              prices=observed_prices,
              strikes=strikes,
              expiries=expiries,
              forwards=forwards,
              is_call_options=is_call_options,
              beta=beta,
              calibrate_beta=False,
              volvol=volvol,
              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,
              optimizer_fn=tff.math.optimizer.bfgs_minimize,
              maximum_iterations=1000,
          )
          return models, is_converged
  
      models, is_converged = fn(
          observed_prices,
          strikes,
          expiries,
          forwards,
          is_call_options,
          beta,
          volvol,
      )
      [
          calibrated_alpha,
          calibrated_beta,
          calibrated_volvol,
          calibrated_rho,
          is_converged,
      ] = self.evaluate(
          [
              models.alpha,
              models.beta,
              models.volvol,
              models.rho,
              is_converged,
          ]
      )
      with self.subTest("AllConverged"):
          self.assertTrue(all(is_converged))
      with self.subTest("AlphaRecovered"):
          self.assertAllClose(
              calibrated_alpha, [1.5, 2.5], atol=2e-3, rtol=2e-3
          )
      with self.subTest("BetaRecovered"):
          self.assertAllClose(
              calibrated_beta, [0.5, 0.5], atol=2e-3, rtol=2e-3
          )
      with self.subTest("VolVolRecovered"):
          self.assertAllClose(
              calibrated_volvol, [0.33, 0.66], atol=2e-2, rtol=5e-2
          )
      with self.subTest("RhoRecovered"):
          self.assertAllClose(
              calibrated_rho, [0.1, -0.1], atol=1e-2, rtol=5e-2
          )
  
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 2 for calling the CalibrationTest obj's underlying member method code with example usage: obj.test_dynamic_shapes() and returns: models,  is_converged