docstr: Tests that volatility follows a log-normal distribution.
docstr_tok: ["Tests","that","volatility","follows","a","log-normal","distribution","."]
code: def test_volatility(
      self,
      beta,
      volvol,
      rho,
      time_step,
      initial_forward=1.0,
      initial_volatility=0.1,
  ):
      """Tests that volatility follows a log-normal distribution."""
      dtype = tf.float64
      times = [0.1, 0.3, 0.5]
      num_samples = 1000
      test_seed = [123, 124]
  
      process = SabrModel(
          beta=beta,
          volvol=volvol,
          rho=rho,
          dtype=dtype,
          enable_unbiased_sampling=True,
      )
      paths = process.sample_paths(
          initial_forward=initial_forward,
          initial_volatility=initial_volatility,
          times=times,
          time_step=time_step,
          num_samples=num_samples,
          seed=test_seed,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
      )
  
      paths = self.evaluate(paths)
      for i in range(len(times)):
          time = times[i]
          path_slice = paths[:, i, 1]
          # Our current implemenation of absorbing bondary conditions leaves one
          # non-positive value, then zeros out future values. Ignore any negative
          # values here for now. However, make sure we're not losing too many
          # samples to the absorbing boundary.
          path_slice = path_slice[path_slice > 0]
          self.assertGreaterEqual(
              len(path_slice),
              num_samples * 0.9,
              msg="Too many invalid samples",
          )
          mean = np.mean(np.log(path_slice))
          stddev = np.std(np.log(path_slice))
          self.assertAllClose(
              (-0.5 * volvol**2 * time, volvol * math.sqrt(time)),
              (mean - math.log(initial_volatility), stddev),
              rtol=0.1,
              atol=0.1,
          )
  
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 1 for calling the SabrModelTest obj's underlying member method code with example usage: obj.test_volatility(beta, volvol, rho, time_step, initial_forward, initial_volatility) without return types