code: def test_compare_monte_carlo_to_european_option(
      self, use_num_time_step, use_time_grid, supply_normal_draws
  ):
      dtype = tf.float64
      mean_reversion_value = 0.3
      theta = 0.05
      volvol = 0.02
      rho = 0.1
      maturity_time = 1.0
      initial_log_spot = 3.0
      initial_vol = 0.05
      strike = 15
      discounting = 0.5
  
      mean_reversion = tff.math.piecewise.PiecewiseConstantFunc(
          jump_locations=[0.1, 0.2],
          values=[
              mean_reversion_value,
              mean_reversion_value,
              mean_reversion_value,
          ],
          dtype=dtype,
      )
  
      heston = HestonModel(
          mean_reversion=mean_reversion,
          theta=theta,
          volvol=volvol,
          rho=rho,
          dtype=dtype,
      )
  
      times = [maturity_time / 2, maturity_time]
      num_samples = 10000
      time_step = None
      times_grid = None
      num_time_steps = None
      normal_draws = None
      seed = [1, 42]
  
      if use_num_time_step:
          num_time_steps = 100
      else:
          time_step = 0.01
      if use_time_grid:
          times_grid = tf.constant(
              np.linspace(0.0, 1.0, 101), dtype=dtype
          )
      if supply_normal_draws:
          num_samples = 1
          # Use antithetic sampling
          normal_draws = tf.random.stateless_normal(
              shape=[5000, 100, 2], seed=seed, dtype=dtype
          )
          normal_draws = tf.concat(
              [normal_draws, -normal_draws], axis=0
          )
      random_type = tff.math.random.RandomType.STATELESS_ANTITHETIC
  
      initial_state = np.array([initial_log_spot, initial_vol])
      samples = heston.sample_paths(
          times=times,
          initial_state=initial_state,
          time_step=time_step,
          num_samples=num_samples,
          random_type=random_type,
          seed=seed,
          num_time_steps=num_time_steps,
          normal_draws=normal_draws,
          times_grid=times_grid,
      )
      self.assertEqual(samples.shape, [10000, 2, 2])
      log_spots = samples[:, -1, 0]
      monte_carlo_price = np.exp(
          -discounting * maturity_time
      ) * tf.math.reduce_mean(
          tf.nn.relu(
              tf.math.exp(log_spots)
              * np.exp(discounting * maturity_time)
              - strike
          )
      )
  
      # Calulating European option price using above parameters
      dtype = np.float64
      variances = initial_vol
      discount_rates = discounting
      expiries = maturity_time
      mean_reversion = mean_reversion_value
  
      spots = np.exp(initial_log_spot)
      forwards = None
  
      european_option_price = self.evaluate(
          tff.models.heston.approximations.european_option_price(
              mean_reversion=mean_reversion,
              theta=theta,
              volvol=volvol,
              rho=rho,
              variances=variances,
              forwards=forwards,
              spots=spots,
              expiries=expiries,
              strikes=strike,
              discount_rates=discount_rates,
              dtype=dtype,
          )
      )
  
      # Comparing monte carlo and european option price
      self.assertAllClose(
          monte_carlo_price, european_option_price, atol=0.1, rtol=0.1
      )
  
file_path: tf-quant-finance/tf_quant_finance/models/heston/heston_model_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 9 for calling the HestonModelTest obj's underlying member method code with example usage: obj.test_compare_monte_carlo_to_european_option(use_num_time_step, use_time_grid, supply_normal_draws) without return types