class_docstr: Tests for methods for the vanilla pricing module.
class_docstr_tok: ["Tests","for","methods","for","the","vanilla","pricing","module","."]
docstr: Tests unit of cash binary option pricing over a wide range of settings.
  
  Uses the fact that if the underlying follows a geometric brownian motion
  then, given the mean on the exponential scale and the variance on the log
  scale, the mean on the log scale is known. In particular for underlying S
  with forward price F, strike K, volatility sig, and expiry T:
  
  log(S) ~ N(log(F) - sig^2 T, sig^2 T)
  
  The price of the binary call option is the discounted probability that S
  will be greater than K at expiry (and for a put option, less than K). Since
  quantiles are preserved under monotonic transformations we can find this
  probability on the log scale. This provides an alternate calculation for the
  same price which we can use to corroborate the standard method.
docstr_tok: ["Tests","unit","of","cash","binary","option","pricing","over","a","wide","range","of","settings",".","Uses","the","fact","that","if","the","underlying","follows","a","geometric","brownian","motion","then",",","given","the","mean","on","the","exponential","scale","and","the","variance","on","the","log","scale",",","the","mean","on","the","log","scale","is","known",".","In","particular","for","underlying","S","with","forward","price","F",",","strike","K",",","volatility","sig",",","and","expiry","T",":","log","(","S",")","~","N","(","log","(","F",")","-","sig^2","T",",","sig^2","T",")","The","price","of","the","binary","call","option","is","the","discounted","probability","that","S","will","be","greater","than","K","at","expiry","(","and","for","a","put","option",",","less","than","K",")",".","Since","quantiles","are","preserved","under","monotonic","transformations","we","can","find","this","probability","on","the","log","scale",".","This","provides","an","alternate","calculation","for","the","same","price","which","we","can","use","to","corroborate","the","standard","method","."]
code: def test_binary_prices_bulk(self):
      """Tests unit of cash binary option pricing over a wide range of settings.
  
      Uses the fact that if the underlying follows a geometric brownian motion
      then, given the mean on the exponential scale and the variance on the log
      scale, the mean on the log scale is known. In particular for underlying S
      with forward price F, strike K, volatility sig, and expiry T:
  
      log(S) ~ N(log(F) - sig^2 T, sig^2 T)
  
      The price of the binary call option is the discounted probability that S
      will be greater than K at expiry (and for a put option, less than K). Since
      quantiles are preserved under monotonic transformations we can find this
      probability on the log scale. This provides an alternate calculation for the
      same price which we can use to corroborate the standard method.
      """
      np.random.seed(321)
      num_examples = 1000
      forwards = np.exp(np.random.normal(size=num_examples))
      strikes = np.exp(np.random.normal(size=num_examples))
      volatilities = np.exp(np.random.normal(size=num_examples))
      expiries = np.random.gamma(
          shape=1.0, scale=1.0, size=num_examples
      )
      log_scale = np.sqrt(expiries) * volatilities
      log_loc = np.log(forwards) - 0.5 * log_scale**2
      call_options = np.random.binomial(n=1, p=0.5, size=num_examples)
      discount_factors = np.random.beta(a=1.0, b=1.0, size=num_examples)
  
      cdf_values = self.evaluate(
          tfp.distributions.Normal(loc=log_loc, scale=log_scale).cdf(
              np.log(strikes)
          )
      )
  
      expected_prices = discount_factors * (
          call_options + ((-1.0) ** call_options) * cdf_values
      )
  
      is_call_options = np.array(call_options, dtype=bool)
      computed_prices = self.evaluate(
          tff.black_scholes.binary_price(
              volatilities=volatilities,
              strikes=strikes,
              expiries=expiries,
              forwards=forwards,
              is_call_options=is_call_options,
              discount_factors=discount_factors,
          )
      )
      self.assertArrayNear(expected_prices, computed_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 10 for calling the VanillaPrice obj's underlying member method code with example usage: obj.test_binary_prices_bulk() without return types