docstr: Explicitly test the code provided in the docstring.
docstr_tok: ["Explicitly","test","the","code","provided","in","the","docstring","."]
code: def test_docstring_example(self):
      """Explicitly test the code provided in the docstring."""
  
      # In this example, we synthetically generate some prices. Then we use our
      # calibration to back out these prices.
      dtype = tf.float64
  
      daycount_fractions = np.array(
          [
              [0.25, 0.25, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0],
              [0.25, 0.25, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0],
              [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25],
              [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25],
          ]
      )
      expiries = np.array(
          [
              [0.0, 0.25, 0.5, 0.75, 1.0, 0.0, 0.0, 0.0],
              [0.0, 0.25, 0.5, 0.75, 1.0, 0.0, 0.0, 0.0],
              [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.50, 1.75],
              [0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.50, 1.75],
          ]
      )
      maturities = np.array(
          [
              [0.25, 0.5, 0.75, 1.0, 0.0, 0.0, 0.0, 0.0],
              [0.25, 0.5, 0.75, 1.0, 0.0, 0.0, 0.0, 0.0],
              [0.25, 0.5, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0],
              [0.25, 0.5, 0.75, 1.0, 1.25, 1.50, 1.75, 2.0],
          ]
      )
      is_cap = np.array([True, False, True, False])
      strikes = 0.01 * np.ones_like(expiries)
  
      # Setup - generate some observed prices using the model.
      expected_mr = [0.4]
      expected_vol = [0.01]
  
      zero_rate_fn = lambda x: 0.01 * tf.ones_like(x)
      prices = tff.models.hull_white.cap_floor_price(
          strikes=strikes,
          expiries=expiries,
          maturities=maturities,
          daycount_fractions=daycount_fractions,
          reference_rate_fn=zero_rate_fn,
          notional=1.0,
          mean_reversion=expected_mr,
          volatility=expected_vol,
          is_cap=tf.expand_dims(is_cap, axis=1),
          use_analytic_pricing=True,
          dtype=dtype,
      )
  
      # Calibrate the model.
      (
          calibrated_result,
          is_converged,
          _,
      ) = tff.models.hull_white.calibration_from_cap_floors(
          prices=prices,
          strikes=strikes,
          expiries=expiries,
          maturities=maturities,
          daycount_fractions=daycount_fractions,
          reference_rate_fn=zero_rate_fn,
          mean_reversion=[0.3],
          volatility=[0.02],
          notional=1.0,
          is_cap=tf.expand_dims(is_cap, axis=1),
          use_analytic_pricing=True,
          optimizer_fn=None,
          num_samples=1000,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[0, 0],
          time_step=0.1,
          maximum_iterations=200,
          dtype=dtype,
      )
  
      calibrated_mr = calibrated_result.mean_reversion.values()
      calibrated_vol = calibrated_result.volatility.values()
  
      calibrated_mr, calibrated_vol = self.evaluate(
          [calibrated_mr, calibrated_vol]
      )
      self.assertTrue(is_converged)
      self.assertAllClose(
          calibrated_mr, expected_mr, atol=1e-3, rtol=1e-2
      )
      self.assertAllClose(
          calibrated_vol, expected_vol, atol=1e-3, rtol=1e-2
      )
  
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 2 for calling the HullWhiteCalibrationCapFloorTest obj's underlying member method code with example usage: obj.test_docstring_example() without return types