docstr: Replicate tests from reference [1] test case 4.
docstr_tok: ["Replicate","tests","from","reference","[","1","]","test","case","4","."]
code: def test_relative_error(self):
      """Replicate tests from reference [1] test case 4."""
      dtype = np.float64
      num_samples = 1000
      test_seed = [123, 124]
  
      initial_forward = tf.constant(0.07, dtype=dtype)
      initial_volatility = tf.constant(0.4, dtype=dtype)
      volvol = tf.constant(0.8, dtype=dtype)
      beta = tf.constant(0.4, dtype=dtype)
      rho = tf.constant(-0.6, dtype=dtype)
      times = [1.0]
      timesteps = [0.0625, 0.03125]
      strike = 0.4
      process = SabrModel(
          beta=beta,
          volvol=volvol,
          rho=rho,
          dtype=dtype,
          enable_unbiased_sampling=True,
      )
      process_table = []
  
      # We compute the relative error across time steps ts for a fixed expiry T:
      # error = | C(T, ts_i) - C(S(T, ts_{i+1})) |
      # where ts_i > ts_{i+1} and C( .. ) is the call option price
      for ts in timesteps:
          paths = process.sample_paths(
              initial_forward=initial_forward,
              initial_volatility=initial_volatility,
              times=times,
              time_step=ts,
              num_samples=num_samples,
              seed=test_seed,
              validate_args=True,
              random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          )
          paths = self.evaluate(paths)
          samples = paths[..., 0]
          price = np.average(np.maximum(samples - strike, 0))
          process_table.append(price)
  
      euler_error = 0.0001681610489796333
      process_error = 0
      for i in range(0, len(timesteps) - 1):
          process_error += np.abs(
              process_table[i] - process_table[i + 1]
          )
      # Average relative error should be lower. Euler error is precomputed
      # for `test_seed` using STATELESS_ANTITHETIC random type.
      self.assertLessEqual(process_error, euler_error)
  
file_path: tf-quant-finance/tf_quant_finance/models/sabr/sabr_model_test.py
imports: import math
  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 import euler_sampling
label_desc: Use image node_id 6 for calling the SabrModelTest obj's underlying member method code with example usage: obj.test_relative_error() without return types