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 that a single sampling asian replicates vanilla prices.
docstr_tok: ["Tests","that","a","single","sampling","asian","replicates","vanilla","prices","."]
code: def test_single_sample_asian_matches_vanilla(self):
      """Tests that a single sampling asian replicates vanilla prices."""
  
      variances = tf.constant([0.09, 0.09, 0.09])
      mean_reversion = tf.constant([1.15, 1.15, 1.15])
      volvol = tf.constant([0.39, 0.39, 0.39])
      theta = tf.constant([0.0348, 0.0348, 0.0348])
      rho = tf.constant([-0.64, -0.64, -0.64])
      spots = tf.constant([100.0, 100.0, 100.0])
      strikes = tf.constant([90.0, 100.0, 110.0])
      discount_rates = tf.constant([0.05, 0.05, 0.05])
      dividend_rates = tf.constant([0.0, 0.0, 0.0])
  
      t_n = tf.constant([1.0], dtype=np.float32)
      expiries = tf.constant([1.0, 1.0, 1.0])
      sampling_times = tf.ones(
          shape=t_n.shape + spots.shape
      ) * tf.expand_dims(t_n, 1)
  
      # Test dynamically shaped sampling_times
      @tf.function(
          input_signature=[
              tf.TensorSpec(shape=[None], dtype=tf.float32),
              tf.TensorSpec(shape=[None], dtype=tf.float32),
              tf.TensorSpec(shape=[None, None], dtype=tf.float32),
          ]
      )
      def asian_option_price_tf(variances, spots, sampling_times):
          return 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,
              dividend_rates=dividend_rates,
          )
  
      computed_prices_asians = asian_option_price_tf(
          variances=variances,
          spots=spots,
          sampling_times=sampling_times,
      )
  
      computed_price_europeans = european_option_price(
          strikes=strikes,
          expiries=expiries,
          spots=spots,
          discount_rates=discount_rates,
          dividend_rates=dividend_rates,
          variances=variances,
          mean_reversion=mean_reversion,
          theta=theta,
          volvol=volvol,
          rho=rho,
      )
  
      self.assertAllClose(
          computed_prices_asians, computed_price_europeans, 1e-4
      )
  
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 2 for calling the AsianPriceTest obj's underlying member method code with example usage: obj.test_single_sample_asian_matches_vanilla() and returns: asian_option_price