docstr: Test that under certain conditions HJM matches analytic HW results.
  
  For the two factor model, when both mean reversions are equivalent, then
  the HJM model matches that of a HW one-factor model with the same mean
  reversion, and effective volatility:
  
    eff_vol = sqrt(vol1^2 + vol2^2 + 2 rho vol1 * vol2)
  
  where rho is the cross correlation between the two factors. In this
  specific test, we assume rho = 0.0.
docstr_tok: ["Test","that","under","certain","conditions","HJM","matches","analytic","HW","results",".","For","the","two","factor","model",",","when","both","mean","reversions","are","equivalent",",","then","the","HJM","model","matches","that","of","a","HW","one-factor","model","with","the","same","mean","reversion",",","and","effective","volatility",":","eff_vol","=","sqrt","(","vol1^2","+","vol2^2","+","2","rho","vol1","*","vol2",")","where","rho","is","the","cross","correlation","between","the","two","factors",".","In","this","specific","test",",","we","assume","rho","=","0.0","."]
code: def test_correctness_2_factor_hull_white_consistency(self):
      """Test that under certain conditions HJM matches analytic HW results.
  
      For the two factor model, when both mean reversions are equivalent, then
      the HJM model matches that of a HW one-factor model with the same mean
      reversion, and effective volatility:
  
        eff_vol = sqrt(vol1^2 + vol2^2 + 2 rho vol1 * vol2)
  
      where rho is the cross correlation between the two factors. In this
      specific test, we assume rho = 0.0.
      """
      error_tol = 1e-3
      dtype = tf.float64
  
      mu = 0.03
      vol1 = 0.02
      vol2 = 0.01
      discount_rate_fn = lambda x: 0.01 * tf.ones_like(x, dtype=dtype)
  
      hjm_price = tff.models.hjm.cap_floor_price(
          strikes=self.strikes,
          expiries=self.expiries,
          maturities=self.maturities,
          daycount_fractions=self.daycount_fractions,
          notional=100.0,
          dim=2,
          mean_reversion=[mu, mu],
          volatility=[vol1, vol2],
          reference_rate_fn=discount_rate_fn,
          num_samples=50000,
          time_step=0.1,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          seed=[1, 2],
          dtype=dtype,
      )
  
      hw_price = tff.models.hull_white.cap_floor_price(
          strikes=self.strikes,
          expiries=self.expiries,
          maturities=self.maturities,
          daycount_fractions=self.daycount_fractions,
          notional=100.0,
          mean_reversion=[mu],
          volatility=[np.sqrt(vol1**2 + vol2**2)],
          reference_rate_fn=discount_rate_fn,
          use_analytic_pricing=True,
          dtype=dtype,
      )
  
      hjm_price = self.evaluate(hjm_price)
      hw_price = self.evaluate(hw_price)
      self.assertAllClose(
          hjm_price, hw_price, rtol=error_tol, atol=error_tol
      )
  
file_path: tf-quant-finance/tf_quant_finance/models/hjm/cap_floor_test.py
imports: import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 8 for calling the HJMCapFloorTest obj's underlying member method code with example usage: obj.test_correctness_2_factor_hull_white_consistency() without return types