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.
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","."]
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.
      """
      dtype = tf.float64
      error_tol = 1e-3
  
      mu = 0.03
      rho = 0.5
      vol1 = 0.02
      vol2 = 0.01
      discount_rate_fn = lambda x: 0.01 * tf.ones_like(x, dtype=dtype)
  
      expiries = np.array([1.0])
      maturities = np.array([5.0])
      strikes = np.exp(-0.01 * maturities) / np.exp(-0.01 * expiries)
  
      hjm_price = tff.models.hjm.bond_option_price(
          strikes=strikes,
          expiries=expiries,
          maturities=maturities,
          dim=2,
          mean_reversion=[mu, mu],
          volatility=[vol1, vol2],
          discount_rate_fn=discount_rate_fn,
          corr_matrix=[[1.0, rho], [rho, 1.0]],
          num_samples=100000,
          time_step=0.05,
          random_type=tff.math.random.RandomType.STATELESS_ANTITHETIC,
          dtype=dtype,
          seed=[1, 2],
      )
      hjm_price = self.evaluate(hjm_price)
  
      hw_price = tff.models.hull_white.bond_option_price(
          strikes=strikes,
          expiries=expiries,
          maturities=maturities,
          mean_reversion=mu,
          volatility=np.sqrt(
              vol1**2 + vol2**2 + 2.0 * rho * vol1 * vol2
          ),
          discount_rate_fn=discount_rate_fn,
          use_analytic_pricing=True,
          dtype=dtype,
      )
      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/zero_coupon_bond_option_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 HJMBondOptionTest obj's underlying member method code with example usage: obj.test_correctness_2_factor_hull_white_consistency() without return types