class_docstr: Represents a batch of cashflows indexed to a CMS rate.
  
  #### Example:
  ```python
  import numpy as np
  import tensorflow as tf
  import tf_quant_finance as tff
  dates = tff.datetime
  instruments = tff.experimental.instruments
  
  start_date = dates.convert_to_date_tensor([(2021, 1, 1)])
  maturity_date = dates.convert_to_date_tensor([(2023, 1, 1)])
  valuation_date = dates.convert_to_date_tensor([(2021, 1, 1)])
  p3m = dates.periods.months(3)
  p6m = dates.periods.months(6)
  p1y = dates.periods.year()
  fix_spec = instruments.FixedCouponSpecs(
      coupon_frequency=p6m,
      currency='usd',
      notional=1.,
      coupon_rate=0.0,  # Not needed
      daycount_convention=instruments.DayCountConvention.ACTUAL_365,
      businessday_rule=dates.BusinessDayConvention.NONE)
  flt_spec = instruments.FloatCouponSpecs(
      coupon_frequency=p3m,
      reference_rate_term=p3m,
      reset_frequency=p3m,
      currency='usd',
      notional=1.,
      businessday_rule=dates.BusinessDayConvention.NONE,
      coupon_basis=0.,
      coupon_multiplier=1.,
      daycount_convention=instruments.DayCountConvention.ACTUAL_365)
  cms_spec = instruments.CMSCouponSpecs(
      coupon_frequency=p3m,
      tenor=p1y,
      float_leg=flt_spec,
      fixed_leg=fix_spec,
      notional=1.,
      coupon_basis=0.,
      coupon_multiplier=1.,
      businessday_rule=None,
      daycount_convention=instruments.DayCountConvention.ACTUAL_365)
  
  cms = instruments.CMSCashflowStream(
      start_date, maturity_date, [cms_spec], dtype=dtype)
  
  curve_dates = valuation_date + dates.periods.years([0, 1, 2, 3, 5])
  reference_curve = instruments.RateCurve(
      curve_dates,
      np.array([
          0.02, 0.02, 0.025, 0.03, 0.035
      ], dtype=np.float64),
      valuation_date=valuation_date,
      dtype=np.float64)
  market = instruments.InterestRateMarket(
      reference_curve=reference_curve, discount_curve=reference_curve)
  
  price = cms.price(valuation_date, market)
  # Expected result: 55512.6295434207
  ```
class_docstr_tok: ["Represents","a","batch","of","cashflows","indexed","to","a","CMS","rate",".","#","#","#","#","Example",":","``","`","python","import","numpy","as","np","import","tensorflow","as","tf","import","tf_quant_finance","as","tff","dates","=","tff.datetime","instruments","=","tff.experimental.instruments","start_date","=","dates.convert_to_date_tensor","(","[","(","2021",",","1",",","1",")","]",")","maturity_date","=","dates.convert_to_date_tensor","(","[","(","2023",",","1",",","1",")","]",")","valuation_date","=","dates.convert_to_date_tensor","(","[","(","2021",",","1",",","1",")","]",")","p3m","=","dates.periods.months","(","3",")","p6m","=","dates.periods.months","(","6",")","p1y","=","dates.periods.year","(",")","fix_spec","=","instruments.FixedCouponSpecs","(","coupon_frequency=p6m",",","currency='usd","'",",","notional=1.",",","coupon_rate=0.0",",","#","Not","needed","daycount_convention=instruments.DayCountConvention.ACTUAL_365",",","businessday_rule=dates.BusinessDayConvention.NONE",")","flt_spec","=","instruments.FloatCouponSpecs","(","coupon_frequency=p3m",",","reference_rate_term=p3m",",","reset_frequency=p3m",",","currency='usd","'",",","notional=1.",",","businessday_rule=dates.BusinessDayConvention.NONE",",","coupon_basis=0.",",","coupon_multiplier=1.",",","daycount_convention=instruments.DayCountConvention.ACTUAL_365",")","cms_spec","=","instruments.CMSCouponSpecs","(","coupon_frequency=p3m",",","tenor=p1y",",","float_leg=flt_spec",",","fixed_leg=fix_spec",",","notional=1.",",","coupon_basis=0.",",","coupon_multiplier=1.",",","businessday_rule=None",",","daycount_convention=instruments.DayCountConvention.ACTUAL_365",")","cms","=","instruments.CMSCashflowStream","(","start_date",",","maturity_date",",","[","cms_spec","]",",","dtype=dtype",")","curve_dates","=","valuation_date","+","dates.periods.years","(","[","0",",","1",",","2",",","3",",","5","]",")","reference_curve","=","instruments.RateCurve","(","curve_dates",",","np.array","(","[","0.02",",","0.02",",","0.025",",","0.03",",","0.035","]",",","dtype=np.float64",")",",","valuation_date=valuation_date",",","dtype=np.float64",")","market","=","instruments.InterestRateMarket","(","reference_curve=reference_curve",",","discount_curve=reference_curve",")","price","=","cms.price","(","valuation_date",",","market",")","#","Expected","result",":","55512.6295434207","``","`"]
docstr: Calculate CMS convexity correction by static replication.
docstr_tok: ["Calculate","CMS","convexity","correction","by","static","replication","."]
code: def _convexity_smile_replication(
      self, valuation_date, market, model, cms_rates, pricing_context
  ):
      """Calculate CMS convexity correction by static replication."""
      normal_model = (
          model
          == rc.InterestRateModelType.NORMAL_SMILE_CONSISTENT_REPLICATION
      )
      swap_vol = tf.convert_to_tensor(
          pricing_context, dtype=self._dtype
      )
      expiry_time = dates.daycount_actual_365_fixed(
          start_date=valuation_date,
          end_date=self._coupon_start_dates,
          dtype=self._dtype,
      )
      lower = tf.zeros_like(cms_rates) + 1e-6
      # TODO(b/154407973): Improve the logic to compute the upper limit.
      rate_limit = 2000.0
      upper = rate_limit * cms_rates
      num_points = 10001
  
      def _call_replication():
          def _intfun_call(x):
              d2fx = self._f_atm_second_derivative(x, cms_rates)
  
              forwards = tf.broadcast_to(
                  tf.expand_dims(cms_rates, -1), x.shape
              )
              expiries = tf.broadcast_to(
                  tf.expand_dims(expiry_time, -1), x.shape
              )
              option_val = _option_prices(
                  volatilities=swap_vol,
                  strikes=x,
                  expiries=expiries,
                  forwards=forwards,
                  is_normal_model=normal_model,
                  dtype=self._dtype,
              )
              return d2fx * option_val
  
          intval_c = integration.integrate(
              _intfun_call, cms_rates, upper, num_points=num_points
          )
          dfk = self._f_atm_first_derivative(cms_rates, cms_rates)
          c_k = _option_prices(
              volatilities=swap_vol,
              strikes=cms_rates,
              expiries=expiry_time,
              forwards=cms_rates,
              is_normal_model=normal_model,
              dtype=self._dtype,
          )
          return (1.0 + dfk) * c_k + intval_c
  
      def _put_replication():
          def _intfun_put(x):
              d2fx = self._f_atm_second_derivative(x, cms_rates)
  
              forwards = tf.broadcast_to(
                  tf.expand_dims(cms_rates, -1), x.shape
              )
              expiries = tf.broadcast_to(
                  tf.expand_dims(expiry_time, -1), x.shape
              )
              option_val = _option_prices(
                  volatilities=swap_vol,
                  strikes=x,
                  expiries=expiries,
                  forwards=forwards,
                  is_call_options=False,
                  is_normal_model=normal_model,
                  dtype=self._dtype,
              )
              return d2fx * option_val
  
          intval_p = integration.integrate(
              _intfun_put, lower, cms_rates, num_points=num_points
          )
          dfk = self._f_atm_first_derivative(cms_rates, cms_rates)
          p_k = _option_prices(
              volatilities=swap_vol,
              strikes=cms_rates,
              expiries=expiry_time,
              forwards=cms_rates,
              is_call_options=False,
              is_normal_model=normal_model,
              dtype=self._dtype,
          )
          return (1.0 + dfk) * p_k - intval_p
  
      call_rep = _call_replication()
      put_rep = _put_replication()
  
      return cms_rates + (call_rep - put_rep)
  
imports: import itertools
  import tensorflow.compat.v2
  import tensorflow_probability
  from tf_quant_finance import black_scholes
  from tf_quant_finance import datetime
  from tf_quant_finance.experimental.instruments import cashflow_stream
  from tf_quant_finance.experimental.instruments import interest_rate_swap
  from tf_quant_finance.experimental.instruments import rates_common
  from tf_quant_finance.math import integration
label_desc: Use image node_id 4 for calling the CMSCashflowStream obj's underlying member method code with example usage: obj._convexity_smile_replication(valuation_date, market, model, cms_rates, pricing_context) and returns: unknown, unknown, unknown, unknown, unknown