docstr: Tests calibration with time-dependent vol parameters.
docstr_tok: ["Tests","calibration","with","time-dependent","vol","parameters","."]
code: def test_correctness_time_dependent_vol(self):
      """Tests calibration with time-dependent vol parameters."""
      dtype = tf.float64
  
      expected_mr = 0.3
      volatility = tff.math.piecewise.PiecewiseConstantFunc(
          jump_locations=[0.5, 2.0],
          values=[0.01, 0.015, 0.02],
          dtype=dtype,
      )
  
      # Setup - generate some observed prices using the model.
      zero_rate_fn = lambda x: 0.01 * tf.ones_like(x)
      prices = tff.models.hull_white.cap_floor_price(
          strikes=self.strikes,
          expiries=self.expiries,
          maturities=self.maturities,
          daycount_fractions=self.daycount_fractions,
          reference_rate_fn=zero_rate_fn,
          notional=1.0,
          mean_reversion=[expected_mr],
          volatility=volatility,
          is_cap=tf.expand_dims(self.is_cap, axis=1),
          use_analytic_pricing=False,
          num_samples=250,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[0, 0],
          time_step=0.1,
          dtype=dtype,
      )
  
      # Calibrate the model.
      (
          calibrated_model,
          is_converged,
          _,
      ) = tff.models.hull_white.calibration_from_cap_floors(
          prices=prices,
          strikes=self.strikes,
          expiries=self.expiries,
          maturities=self.maturities,
          daycount_fractions=self.daycount_fractions,
          reference_rate_fn=zero_rate_fn,
          mean_reversion=[0.4],
          volatility=volatility,
          notional=1.0,
          is_cap=tf.expand_dims(self.is_cap, axis=1),
          use_analytic_pricing=False,
          num_samples=250,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[0, 0],
          time_step=0.1,
          maximum_iterations=200,
          dtype=dtype,
      )
  
      vol = calibrated_model.volatility.values()
      vol = self.evaluate(vol)
  
      # Assert model convergence to expected parameters.
      self.assertTrue(is_converged)
  
      # Assert that the calibrated y-values of the piecewise-constant function are
      # close to the true values.
      self.assertAllClose(
          vol, [0.01, 0.015, 0.02], atol=1e-3, rtol=1e-3
      )
  
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 4 for calling the HullWhiteCalibrationCapFloorTest obj's underlying member method code with example usage: obj.test_correctness_time_dependent_vol() without return types