class_docstr: 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_replicating_weights(self, strikes):
      """Tests ability to match 'hand' calculated variance replicating weights."""
      reference_strikes = 100.0
      delta_strike = 10.0
      expiries = 1.0
      # This is the value of (A 4) in Demeterfi et al.
      payoff_values = 2 * (
          (strikes - reference_strikes) / reference_strikes
          - np.log(strikes / reference_strikes)
      )
      # This is the value of the ratio term in (A 7) in Demeterfi et al.
      slope_values = np.diff(payoff_values / delta_strike)
      # Literal calculation of (A 7/8) for all weights. The library uses
      # first differences rather than cumsums for efficiency due to algebra.
      expected_weights = []
      for v in slope_values:
          expected_weights.append(v - np.sum(expected_weights))
      weights = self.evaluate(
          variance_swaps.replicating_weights(
              strikes, reference_strikes, expiries, dtype=tf.float64
          )
      )
      self.assertAllClose(weights, expected_weights, 1e-6)
  
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 1 for calling the VarianceSwapsTest obj's underlying member method code with example usage: obj.test_replicating_weights(strikes) without return types