class_docstr: Tests for methods for the vanilla pricing module.
class_docstr_tok: ["Tests","for","methods","for","the","vanilla","pricing","module","."]
docstr: Tests that the gradient exists, and is also right-continuous.
docstr_tok: ["Tests","that","the","gradient","exists",",","and","is","also","right-continuous","."]
code: def test_vanilla_options_price_gradient_continuous(
      self, vol, strikes, expiries, forwards, is_call, is_normal
  ):
      """Tests that the gradient exists, and is also right-continuous."""
      dtype = tf.float64
      vol = tf.convert_to_tensor(vol, dtype=dtype)
      strikes = tf.convert_to_tensor(strikes, dtype=dtype)
      expiries = tf.convert_to_tensor(expiries, dtype=dtype)
      forwards = tf.convert_to_tensor(forwards, dtype=dtype)
  
      with tf.GradientTape(persistent=True) as tape:
          tape.watch([vol, strikes, expiries, forwards])
          price = tff.black_scholes.option_price(
              volatilities=vol,
              strikes=strikes,
              expiries=expiries,
              forwards=forwards,
              is_call_options=is_call,
              is_normal_volatility=is_normal,
              dtype=dtype,
          )
          grad = tape.gradient(
              target=price, sources=[vol, strikes, expiries, forwards]
          )
  
      grad = self.evaluate(grad)
      self.assertTrue(all(np.all(np.isfinite(x)) for x in grad))
  
      with tf.GradientTape(persistent=True) as tape:
          tape.watch([vol, strikes, expiries, forwards])
          price_perturb_vol = tff.black_scholes.option_price(
              volatilities=vol + 1e-6,
              strikes=strikes,
              expiries=expiries,
              forwards=forwards,
              is_call_options=is_call,
              is_normal_volatility=is_normal,
              dtype=dtype,
          )
          grad_perturb_vol = tape.gradient(
              target=price_perturb_vol,
              sources=[vol, strikes, expiries, forwards],
          )
  
      grad_perturb_vol = self.evaluate(grad_perturb_vol)
      self.assertAllClose(grad, grad_perturb_vol, rtol=1e-4)
  
      with tf.GradientTape(persistent=True) as tape:
          tape.watch([vol, strikes, expiries, forwards])
          price_perturb_expiries = tff.black_scholes.option_price(
              volatilities=vol,
              strikes=strikes,
              expiries=expiries + 1e-6,
              forwards=forwards,
              is_call_options=is_call,
              is_normal_volatility=is_normal,
              dtype=dtype,
          )
          grad_perturb_expiries = tape.gradient(
              target=price_perturb_expiries,
              sources=[vol, strikes, expiries, forwards],
          )
  
      grad_perturb_expiries = self.evaluate(grad_perturb_expiries)
      self.assertAllClose(grad, grad_perturb_expiries, rtol=1e-4)
  
      with tf.GradientTape(persistent=True) as tape:
          tape.watch([vol, strikes, expiries, forwards])
          price_perturb_strikes = tff.black_scholes.option_price(
              volatilities=vol,
              strikes=strikes + 1e-6,
              expiries=expiries,
              forwards=forwards,
              is_call_options=is_call,
              is_normal_volatility=is_normal,
              dtype=dtype,
          )
          grad_perturb_strikes = tape.gradient(
              target=price_perturb_strikes,
              sources=[vol, strikes, expiries, forwards],
          )
  
      grad_perturb_strikes = self.evaluate(grad_perturb_strikes)
      self.assertAllClose(grad, grad_perturb_strikes, rtol=1e-4)
  
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 15 for calling the VanillaPrice obj's underlying member method code with example usage: obj.test_vanilla_options_price_gradient_continuous(vol, strikes, expiries, forwards, is_call, is_normal) without return types