class_docstr: Tests for methods for the Heston asian pricing module.
class_docstr_tok: ["Tests","for","methods","for","the","Heston","asian","pricing","module","."]
docstr: Tests for methods for the asian pricing module a seasoned asian option.
      
docstr_tok: ["Tests","for","methods","for","the","asian","pricing","module","a","seasoned","asian","option","."]
code: def test_seasoned_analytic_vs_monte_carlo(self):
      """Tests for methods for the asian pricing module a seasoned asian option."""
      # Results are compared to a Monte Carlo simulation.
  
      variances = 0.09
      mean_reversion = 1.15
      volvol = 0.39
      theta = 0.0348
      rho = -0.64
      spots = 100.0
      strikes = [90.0, 100.0, 110.0]
      discount_rates = 0.0
  
      expiries = 1.0
      sampling_times = np.linspace(0.25, expiries, 4)[:, np.newaxis]
      past_fixings = [100.0, 100.0, 100.0]
  
      computed_prices_asians = asian_option_price(
          variances=variances,
          mean_reversion=mean_reversion,
          theta=theta,
          volvol=volvol,
          rho=rho,
          strikes=strikes,
          expiries=expiries,
          spots=spots,
          sampling_times=sampling_times,
          discount_rates=discount_rates,
          past_fixings=past_fixings,
      )
  
      dtype = np.float64
      num_samples = 100000
      num_timesteps = 24
  
      dt = 1.0 / num_timesteps
      strikes_tensor = tf.constant(strikes, dtype=dtype)
      times = tf.constant(np.linspace(0.25, expiries, 4), dtype=dtype)
      log_spot = np.log(spots)
  
      total_fixings = len(past_fixings) + times.shape[0]
      running_accumulator = np.prod(past_fixings)
  
      process = tff.models.heston.HestonModel(
          mean_reversion=mean_reversion,
          theta=theta,
          volvol=volvol,
          rho=rho,
          dtype=dtype,
      )
  
      initial_state = tf.constant([log_spot, variances], dtype=dtype)
      paths = process.sample_paths(
          times,
          initial_state,
          time_step=dt,
          num_samples=num_samples,
          seed=123,
      )
  
      prefactor = running_accumulator ** (1 / total_fixings)
      spot_prods = prefactor * tf.math.exp(
          tf.reduce_sum(paths[:, :, 0], axis=1) / total_fixings
      )
      spot_prods = tf.broadcast_to(
          tf.expand_dims(spot_prods, 1),
          spot_prods.shape + strikes_tensor.shape,
      )
      payoffs = tf.nn.relu(spot_prods - strikes_tensor)
      mc_prices = tf.math.reduce_mean(payoffs, 0)
  
      self.assertAllClose(computed_prices_asians, mc_prices, 1e-2)
  
file_path: tf-quant-finance/tf_quant_finance/models/heston/approximations/asian_prices_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 AsianPriceTest obj's underlying member method code with example usage: obj.test_seasoned_analytic_vs_monte_carlo() without return types