class_docstr: Tests for the variance_swaps module.
class_docstr_tok: ["Tests","for","the","variance_swaps","module","."]
docstr: Tests ability to match 'hand' calculated variance replicating weights.
docstr_tok: ["Tests","ability","to","match","'hand","'","calculated","variance","replicating","weights","."]
code: def test_variance_swap_demeterfi_example(
      self,
      call_strikes,
      call_weights,
      call_volatilities,
      put_strikes,
      put_weights,
      put_volatilities,
      reference_strikes,
      expiries,
      discount_rates,
      tolerance,
      k_var,
  ):
      """Tests ability to match 'hand' calculated variance replicating weights."""
      # Paper quotes weights inflated to forward values.
      discount_factor = np.exp(discount_rates * expiries)
      calculated_call_weights = self.evaluate(
          variance_swaps.replicating_weights(
              call_strikes,
              reference_strikes,
              expiries,
              dtype=tf.float64,
          )
      )
      matched_call_weights = (
          discount_factor * 100.0**2 * calculated_call_weights
      )
      self.assertAllClose(matched_call_weights, call_weights, tolerance)
      calculated_put_weights = self.evaluate(
          variance_swaps.replicating_weights(
              put_strikes, reference_strikes, expiries, dtype=tf.float64
          )
      )
      matched_put_weights = (
          discount_factor * 100.0**2 * calculated_put_weights
      )
      self.assertAllClose(matched_put_weights, put_weights, tolerance)
      variance_price = self.evaluate(
          tff.black_scholes.variance_swap_fair_strike(
              put_strikes,
              put_volatilities,
              call_strikes,
              call_volatilities,
              expiries,
              discount_rates,
              reference_strikes,
              reference_strikes,
              dtype=tf.float64,
          )
      )
      self.assertAllClose(variance_price, k_var, 1e-2)
  
file_path: tf-quant-finance/tf_quant_finance/black_scholes/variance_swaps_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tf_quant_finance.black_scholes import variance_swaps
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 4 for calling the VarianceSwapsTest obj's underlying member method code with example usage: obj.test_variance_swap_demeterfi_example(call_strikes, call_weights, call_volatilities, put_strikes, put_weights, put_volatilities, reference_strikes, expiries, discount_rates, tolerance, k_var) without return types