class_docstr: Tests for methods for the vanilla pricing module.
class_docstr_tok: ["Tests","for","methods","for","the","vanilla","pricing","module","."]
docstr: Tests the consistency between vanilla and binary option prices.
docstr_tok: ["Tests","the","consistency","between","vanilla","and","binary","option","prices","."]
code: def test_vanilla_and_binary_prices_consistency_bulk(
      self, discount_mode, is_normal
  ):
      """Tests the consistency between vanilla and binary option prices."""
  
      # A vanilla call is equivalent to the combination of a long asset-or-nothing
      # call and short {strike} units of cash-or-nothing calls.
      # A vanilla put is equivalent to the combination of a long {strike} units of
      # cash-or-nothing puts and an short asset-or-nothing put.
      # This test confirms that the computed vanilla and binary option prices are
      # consistent with the above relations for a range of simulated settings.
  
      np.random.seed(321)
      num_examples = 1000
      volatilities = np.exp(np.random.normal(size=num_examples))
      strikes = np.exp(np.random.normal(size=num_examples))
      expiries = np.random.gamma(
          shape=1.0, scale=1.0, size=num_examples
      )
      forwards = np.exp(np.random.normal(size=num_examples))
      if discount_mode == "rates":
          discount_rates = np.random.uniform(
              0.0, 0.05, size=num_examples
          )
          discount_factors = None
      else:
          discount_factors = np.random.beta(
              a=1.0, b=1.0, size=num_examples
          )
          discount_rates = None
      dividend_rates = np.random.uniform(0.0, 0.05, size=num_examples)
      call_options = np.random.binomial(n=1, p=0.5, size=num_examples)
      is_call_options = np.array(call_options, dtype=bool)
  
      asset_or_nothing_prices = (
          tff.black_scholes.asset_or_nothing_price(
              volatilities=volatilities,
              strikes=strikes,
              expiries=expiries,
              forwards=forwards,
              discount_rates=discount_rates,
              dividend_rates=dividend_rates,
              is_call_options=is_call_options,
              is_normal_volatility=is_normal,
              discount_factors=discount_factors,
          )
      )
      cash_or_nothing_prices = tff.black_scholes.binary_price(
          volatilities=volatilities,
          strikes=strikes,
          expiries=expiries,
          forwards=forwards,
          discount_rates=discount_rates,
          dividend_rates=dividend_rates,
          is_call_options=is_call_options,
          is_normal_volatility=is_normal,
          discount_factors=discount_factors,
      )
      synthetic_vanilla_from_binary_prices = tf.where(
          is_call_options,
          asset_or_nothing_prices - strikes * cash_or_nothing_prices,
          strikes * cash_or_nothing_prices - asset_or_nothing_prices,
      )
  
      directly_computed_vanilla_prices = tff.black_scholes.option_price(
          volatilities=volatilities,
          strikes=strikes,
          expiries=expiries,
          forwards=forwards,
          discount_rates=discount_rates,
          dividend_rates=dividend_rates,
          is_call_options=is_call_options,
          is_normal_volatility=is_normal,
          discount_factors=discount_factors,
      )
  
      self.assertArrayNear(
          self.evaluate(synthetic_vanilla_from_binary_prices),
          self.evaluate(directly_computed_vanilla_prices),
          1e-10,
      )
  
imports: import functools
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tensorflow_probability
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 14 for calling the VanillaPrice obj's underlying member method code with example usage: obj.test_vanilla_and_binary_prices_consistency_bulk(discount_mode, is_normal) without return types