docstr: Tests the expected total var calculation matches Monte Carlo results.
docstr_tok: ["Tests","the","expected","total","var","calculation","matches","Monte","Carlo","results","."]
code: def test_expected_var_mc(self):
      """Tests the expected total var calculation matches Monte Carlo results."""
  
      # Define process
      initial_var = 0.1
      rho = -0.5
      volvol = 1.0
      mean_reversion = 10.0
      theta = 0.04
      dtype = tf.float64
      process = HestonModel(
          mean_reversion=mean_reversion,
          theta=theta,
          volvol=volvol,
          rho=rho,
          dtype=dtype,
      )
  
      # Draw paths
      num_samples = 10000
      num_times = 252
      initial_state = tf.constant([1.0, initial_var], dtype=dtype)
      future_time = 1.0
      times = tf.constant(
          np.linspace(0, future_time, num_times), dtype=dtype
      )
      time_step = 0.1
      paths = process.sample_paths(
          times,
          initial_state,
          time_step=time_step,
          num_samples=num_samples,
          seed=123,
      )
  
      # Monte carlo estimate of discretized integral.
      mc_estimate_var = self.evaluate(
          tf.math.reduce_mean(
              tf.math.reduce_sum(
                  tff.math.diff(times) * paths[:, :, 1], axis=1
              )
          )
      )
  
      # Compare to total var from formula implementation.
      expected_var = self.evaluate(
          process.expected_total_variance(future_time, initial_var)
      )
      np.testing.assert_allclose(
          expected_var, mc_estimate_var, rtol=0.01
      )
  
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 4 for calling the HestonModelTest obj's underlying member method code with example usage: obj.test_expected_var_mc() without return types