docstr: Tests univariate GBM time varying drift and volatility functions.
docstr_tok: ["Tests","univariate","GBM","time","varying","drift","and","volatility","functions","."]
code: def test_univariate_time_varying_drift_and_volatility(self, dtype):
      """Tests univariate GBM time varying drift and volatility functions."""
      # Generate times series for the drift and volatility.
      times = np.linspace(0.0, 10.0, 6, dtype=dtype)
      drift = np.append([0.0], np.sin(times, dtype=dtype))
      sigma = np.append([0.0], np.cos(times, dtype=dtype)) ** 2.0
      drift_in = tff.math.piecewise.PiecewiseConstantFunc(
          jump_locations=times, values=drift, dtype=dtype
      )
      sigma_in = tff.math.piecewise.PiecewiseConstantFunc(
          jump_locations=times, values=sigma, dtype=dtype
      )
      process = tff.models.GeometricBrownianMotion(
          drift_in, sigma_in, dtype=dtype
      )
      drift_fn = process.drift_fn()
      volatility_fn = process.volatility_fn()
      state = np.array([[1.0], [2.0], [3.0]], dtype=dtype)
      test_times = np.array([1.0, 3.5, 7.5, 9.8, 12], dtype=dtype)
      expected_drift = drift_in(test_times)
      expected_sigma = sigma_in(test_times)
  
      with self.subTest("Drift"):
          drift = drift_fn(test_times, state)
          self.assertAllClose(
              drift, expected_drift * state, atol=1e-8, rtol=1e-8
          )
  
      with self.subTest("Volatility"):
          vol = volatility_fn(test_times, state)
          self.assertAllClose(
              vol,
              expected_sigma * tf.expand_dims(state, -1),
              atol=1e-8,
              rtol=1e-8,
          )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
  from tf_quant_finance.models.geometric_brownian_motion import geometric_brownian_motion_test_utils
  from tf_quant_finance.models.geometric_brownian_motion import univariate_geometric_brownian_motion
label_desc: Use image node_id 3 for calling the GeometricBrownianMotionTest obj's underlying member method code with example usage: obj.test_univariate_time_varying_drift_and_volatility(dtype) without return types