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: Setup tensors for efficient computations.
docstr_tok: ["Setup","tensors","for","efficient","computations","."]
code: def _setup(self, coupon_spec):
      """Setup tensors for efficient computations."""
  
      cpn_frequency = dates.PeriodTensor.stack(
          [x.coupon_frequency for x in coupon_spec], axis=0
      )
      cpn_dates, _ = self._generate_schedule(
          cpn_frequency, coupon_spec[-1].businessday_rule
      )
      cms_start_dates = cpn_dates[:, :-1]
      cms_term = dates.PeriodTensor.stack(
          [x.tenor for x in coupon_spec], axis=0
      )
  
      cms_end_dates = cpn_dates[:, :-1] + cms_term.expand_dims(
          axis=-1
      ).broadcast_to(cms_start_dates.shape)
      coupon_start_dates = cpn_dates[:, :-1]
      coupon_end_dates = cpn_dates[:, 1:]
      payment_dates = cpn_dates[:, 1:]
  
      daycount_fractions = rc.get_daycount_fraction(
          coupon_start_dates,
          coupon_end_dates,
          coupon_spec[-1].daycount_convention,
          dtype=self._dtype,
      )
  
      notional = tf.repeat(
          tf.convert_to_tensor(
              [x.notional for x in coupon_spec], dtype=self._dtype
          ),
          payment_dates.shape.as_list()[-1],
      )
  
      coupon_basis = tf.repeat(
          tf.convert_to_tensor(
              [x.coupon_basis for x in coupon_spec], dtype=self._dtype
          ),
          payment_dates.shape.as_list()[-1],
      )
  
      coupon_multiplier = tf.repeat(
          tf.convert_to_tensor(
              [x.coupon_multiplier for x in coupon_spec],
              dtype=self._dtype,
          ),
          payment_dates.shape.as_list()[-1],
      )
  
      contract_index = tf.repeat(
          tf.range(0, len(coupon_spec)),
          payment_dates.shape.as_list()[-1],
      )
  
      cms_fixed_leg = [x.fixed_leg for x in coupon_spec]
      cms_float_leg = [x.float_leg for x in coupon_spec]
      self._num_cashflows = daycount_fractions.shape.as_list()[-1]
      self._swap = irs.InterestRateSwap(
          cms_start_dates.reshape([-1]),
          cms_end_dates.reshape([-1]),
          list(
              itertools.chain.from_iterable(
                  itertools.repeat(i, self._num_cashflows)
                  for i in cms_fixed_leg
              )
          ),
          list(
              itertools.chain.from_iterable(
                  itertools.repeat(i, self._num_cashflows)
                  for i in cms_float_leg
              )
          ),
          dtype=self._dtype,
      )
      self._coupon_start_dates = coupon_start_dates.reshape([-1])
      self._coupon_end_dates = coupon_end_dates.reshape([-1])
      self._payment_dates = payment_dates.reshape([-1])
      self._notional = notional
      self._daycount_fractions = tf.reshape(daycount_fractions, [-1])
      self._coupon_basis = coupon_basis
      self._coupon_multiplier = coupon_multiplier
      self._contract_index = contract_index
  
      # convexity related values
      def term_to_years(t):
          frac = tf.where(
              t.period_type() == dates.PeriodType.MONTH,
              tf.constant(1.0 / 12.0, dtype=self._dtype),
              tf.where(
                  t.period_type() == dates.PeriodType.YEAR,
                  tf.constant(1.0, dtype=self._dtype),
                  tf.constant(0.0, dtype=self._dtype),
              ),
          )
          return frac * tf.cast(t.quantity(), dtype=self._dtype)
  
      cms_fixed_leg_frequency = dates.PeriodTensor.stack(
          [x.fixed_leg.coupon_frequency for x in coupon_spec], axis=0
      )
      self._delta = term_to_years(cpn_frequency)
      self._tau = term_to_years(cms_fixed_leg_frequency)
      self._cms_periods = term_to_years(cms_term) / self._tau
  
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 5 for calling the CMSCashflowStream obj's underlying member method code with example usage: obj._setup(coupon_spec) and returns: unknown