class_docstr: Represents a batch of Interest Rate Swaps (IRS).
  
  An Interest rate swap (IRS) is a contract between two counterparties for an
  exchange of a series of payments over a period of time. The payments are made
  periodically (for example quarterly or semi-annually) where the last payment
  is made at the maturity (or termination) of the contract. In the case of
  fixed-for-floating IRS, one counterparty pays a fixed rate while the other
  counterparty's payments are linked to a floating index, most commonly the
  LIBOR rate. On the other hand, in the case of interest rate basis swap, the
  payments of both counterparties are linked to a floating index. Typically, the
  floating rate is observed (or fixed) at the beginning of each period while the
  payments are made at the end of each period [1].
  
  For example, consider a vanilla swap with the starting date T_0 and maturity
  date T_n and equally spaced coupon payment dates T_1, T_2, ..., T_n such that
  
  T_0 < T_1 < T_2 < ... < T_n and dt_i = T_(i+1) - T_i    (A)
  
  The floating rate is fixed on T_0, T_1, ..., T_(n-1) and both the fixed and
  floating payments are made on T_1, T_2, ..., T_n (payment dates).
  
  The InterestRateSwap class can be used to create and price multiple IRS
  simultaneously. The class supports vanilla fixed-for-floating swaps as
  well as basis swaps. However all IRS within an IRS object must be priced using
  a common reference and discount curve.
  
  #### Example (non batch):
  The following example illustrates the construction of an IRS instrument and
  calculating its price.
  
  ```python
  DayCountConventions = daycount_conventions.DayCountConventions
  BusinessDayConvention = business_days.BusinessDayConvention
  RateIndex = instrument_protos.rate_indices.RateIndex
  Currency = currencies.Currency
  
  swap = ir_swap.InterestRateSwap(
      effective_date=date_pb2.Date(year=2020, month=2, day=2),
      maturity_date=date_pb2.Date(year=2023, month=2, day=2),
      currency=Currency.USD(),
      pay_leg=ir_swap.SwapLeg(
          fixed_leg=ir_swap.FixedLeg(
              currency=Currency.USD(),
              coupon_frequency=period_pb2.Period(type="MONTH", amount=6),
              notional_amount=decimal_pb2.Decimal(units=10000),
              fixed_rate=decimal_pb2.Decimal(nanos=31340000),
              daycount_convention=DayCountConventions.ACTUAL_365(),
              business_day_convention=BusinessDayConvention.
                MODIFIED_FOLLOWING(),
              settlement_days=0)),
      receive_leg=ir_swap.SwapLeg(
          floating_leg=ir_swap.FloatingLeg(
              currency=Currency.USD(),
              coupon_frequency=period_pb2.Period(type="MONTH", amount=3),
              reset_frequency=period_pb2.Period(type="MONTH", amount=3),
              notional_amount=decimal_pb2.Decimal(units=10000),
              floating_rate_type=RateIndex(type="LIBOR_3M"),
              daycount_convention=DayCountConventions.ACTUAL_365(),
              business_day_convention=BusinessDayConvention.
                MODIFIED_FOLLOWING(),
              settlement_days=0)))
    dates = [[2021, 2, 8], [2022, 2, 8], [2023, 2, 8], [2025, 2, 8],
             [2027, 2, 8], [2030, 2, 8], [2050, 2, 8]]
    discounts = [0.97197441, 0.94022746, 0.91074031, 0.85495089, 0.8013675,
                 0.72494879, 0.37602059]
    libor_3m_config = {
        "interpolation_method": interpolation_method.InterpolationMethod.LINEAR
    }
    self._market_data_dict = {
        "rates": {
            "USD": {
                "risk_free_curve": {
                    "dates": dates,
                    "discounts": discounts,
                },
                "LIBOR_3M": {
                    "dates": dates,
                    "discounts": discounts,
                    "config": libor_3m_config,
                }
            }
        },
        "reference_date": [(2020, 6, 24)],
    }
  market = market_data.MarketDataDict(market_data_dict)
  swaps = interest_rate_swap.InterestRateSwap.from_protos([swap])
  swaps[0].price(market)
  # Expected: [-69.42497649]
  ```
  
  #### References:
  [1]: Leif B.G. Andersen and Vladimir V. Piterbarg. Interest Rate Modeling,
      Volume I: Foundations and Vanilla Models. Chapter 5. 2010.
docstr: Initializes a batch of IRS contracts.
  
  Args:
    pay_leg: An instance of `FixedCouponSpecs` or `FloatCouponSpecs`, or
      a dictionary specifying the coupon payments for the payment leg of the
      swap.
    receive_leg: An instance of `FixedCouponSpecs` or `FloatCouponSpecs`, or
      a dictionary specifying the coupon payments for the receiving leg of th
      swap.
    start_date: A `DateTensor` of `batch_shape` specifying the dates for the
      inception (start of the accrual) of the swap contracts. `batch_shape`
      corresponds to the number of instruments being created. Either this
      or `pay_leg_schedule` and `receive_leg_schedule` should be provided.
    maturity_date: A `DateTensor` broadcastable with `start_date` specifying
      the maturity dates for each contract. Either this
      or `pay_leg_schedule` and `receive_leg_schedule` should be provided.
    pay_leg_schedule_fn:  A callable that accepts `start_date`, `end_date`,
      `coupon_frequency`, `settlement_days`, `first_coupon_date`, and
      `penultimate_coupon_date` as `Tensor`s and returns coupon payment
      days. Constructs schedule for the pay leg of the swap.
      Default value: `None`.
    pay_leg_schedule: A `DateTensor` of coupon payment dates for the pay leg.
    receive_leg_schedule_fn:  A callable that accepts `start_date`,
      `end_date`, `coupon_frequency`, `settlement_days`, `first_coupon_date`,
      and `penultimate_coupon_date` as `Tensor`s and returns coupon payment
      days. Constructs schedule for the receive leg of the swap.
      Default value: `None`.
    receive_leg_schedule: A `DateTensor` of coupon payment dates for the
      receive leg.
    config: Optional `InterestRateSwapConfig` or a dictionary.
      If dictionary, then the keys should be the same as the field names of
      `InterestRateSwapConfig`.
    batch_names: A string `Tensor` of instrument names. Should be of shape
      `batch_shape + [2]` specying name and instrument type. This is useful
      when the `from_protos` method is used and the user needs to identify
      which instruments got batched together.
    dtype: `tf.Dtype` of the input and output real `Tensor`s.
      Default value: None which maps to the default dtype inferred by
      TensorFlow.
    name: Python str. The name to give to the ops created by this class.
      Default value: `None` which maps to 'interest_rate_swap'.
docstr_tok: ["Initializes","a","batch","of","IRS","contracts",".","Args",":","pay_leg",":","An","instance","of","`","FixedCouponSpecs","`","or","`","FloatCouponSpecs","`",",","or","a","dictionary","specifying","the","coupon","payments","for","the","payment","leg","of","the","swap",".","receive_leg",":","An","instance","of","`","FixedCouponSpecs","`","or","`","FloatCouponSpecs","`",",","or","a","dictionary","specifying","the","coupon","payments","for","the","receiving","leg","of","th","swap",".","start_date",":","A","`","DateTensor","`","of","`","batch_shape","`","specifying","the","dates","for","the","inception","(","start","of","the","accrual",")","of","the","swap","contracts",".","`","batch_shape","`","corresponds","to","the","number","of","instruments","being","created",".","Either","this","or","`","pay_leg_schedule","`","and","`","receive_leg_schedule","`","should","be","provided",".","maturity_date",":","A","`","DateTensor","`","broadcastable","with","`","start_date","`","specifying","the","maturity","dates","for","each","contract",".","Either","this","or","`","pay_leg_schedule","`","and","`","receive_leg_schedule","`","should","be","provided",".","pay_leg_schedule_fn",":","A","callable","that","accepts","`","start_date","`",",","`","end_date","`",",","`","coupon_frequency","`",",","`","settlement_days","`",",","`","first_coupon_date","`",",","and","`","penultimate_coupon_date","`","as","`","Tensor","`","s","and","returns","coupon","payment","days",".","Constructs","schedule","for","the","pay","leg","of","the","swap",".","Default","value",":","`","None","`",".","pay_leg_schedule",":","A","`","DateTensor","`","of","coupon","payment","dates","for","the","pay","leg",".","receive_leg_schedule_fn",":","A","callable","that","accepts","`","start_date","`",",","`","end_date","`",",","`","coupon_frequency","`",",","`","settlement_days","`",",","`","first_coupon_date","`",",","and","`","penultimate_coupon_date","`","as","`","Tensor","`","s","and","returns","coupon","payment","days",".","Constructs","schedule","for","the","receive","leg","of","the","swap",".","Default","value",":","`","None","`",".","receive_leg_schedule",":","A","`","DateTensor","`","of","coupon","payment","dates","for","the","receive","leg",".","config",":","Optional","`","InterestRateSwapConfig","`","or","a","dictionary",".","If","dictionary",",","then","the","keys","should","be","the","same","as","the","field","names","of","`","InterestRateSwapConfig","`",".","batch_names",":","A","string","`","Tensor","`","of","instrument","names",".","Should","be","of","shape","`","batch_shape","+","[","2","]","`","specying","name","and","instrument","type",".","This","is","useful","when","the","`","from_protos","`","method","is","used","and","the","user","needs","to","identify","which","instruments","got","batched","together",".","dtype",":","`","tf.Dtype","`","of","the","input","and","output","real","`","Tensor","`","s",".","Default","value",":","None","which","maps","to","the","default","dtype","inferred","by","TensorFlow",".","name",":","Python","str",".","The","name","to","give","to","the","ops","created","by","this","class",".","Default","value",":","`","None","`","which","maps","to","'interest_rate_swap","'","."]
code: def __init__(
      self,
      *,
      pay_leg: Union[
          coupon_specs.FixedCouponSpecs,
          coupon_specs.FloatCouponSpecs,
          Dict[str, Any],
      ],
      receive_leg: Union[
          coupon_specs.FixedCouponSpecs,
          coupon_specs.FloatCouponSpecs,
          Dict[str, Any],
      ],
      start_date: types.DateTensor = None,
      maturity_date: types.DateTensor = None,
      pay_leg_schedule_fn=None,
      pay_leg_schedule=None,
      receive_leg_schedule_fn=None,
      receive_leg_schedule=None,
      config: Union[InterestRateSwapConfig, Dict[str, Any]] = None,
      batch_names: Optional[tf.Tensor] = None,
      dtype: Optional[types.Dtype] = None,
      name: Optional[str] = None,
  ):
      """Initializes a batch of IRS contracts.
  
      Args:
        pay_leg: An instance of `FixedCouponSpecs` or `FloatCouponSpecs`, or
          a dictionary specifying the coupon payments for the payment leg of the
          swap.
        receive_leg: An instance of `FixedCouponSpecs` or `FloatCouponSpecs`, or
          a dictionary specifying the coupon payments for the receiving leg of th
          swap.
        start_date: A `DateTensor` of `batch_shape` specifying the dates for the
          inception (start of the accrual) of the swap contracts. `batch_shape`
          corresponds to the number of instruments being created. Either this
          or `pay_leg_schedule` and `receive_leg_schedule` should be provided.
        maturity_date: A `DateTensor` broadcastable with `start_date` specifying
          the maturity dates for each contract. Either this
          or `pay_leg_schedule` and `receive_leg_schedule` should be provided.
        pay_leg_schedule_fn:  A callable that accepts `start_date`, `end_date`,
          `coupon_frequency`, `settlement_days`, `first_coupon_date`, and
          `penultimate_coupon_date` as `Tensor`s and returns coupon payment
          days. Constructs schedule for the pay leg of the swap.
          Default value: `None`.
        pay_leg_schedule: A `DateTensor` of coupon payment dates for the pay leg.
        receive_leg_schedule_fn:  A callable that accepts `start_date`,
          `end_date`, `coupon_frequency`, `settlement_days`, `first_coupon_date`,
          and `penultimate_coupon_date` as `Tensor`s and returns coupon payment
          days. Constructs schedule for the receive leg of the swap.
          Default value: `None`.
        receive_leg_schedule: A `DateTensor` of coupon payment dates for the
          receive leg.
        config: Optional `InterestRateSwapConfig` or a dictionary.
          If dictionary, then the keys should be the same as the field names of
          `InterestRateSwapConfig`.
        batch_names: A string `Tensor` of instrument names. Should be of shape
          `batch_shape + [2]` specying name and instrument type. This is useful
          when the `from_protos` method is used and the user needs to identify
          which instruments got batched together.
        dtype: `tf.Dtype` of the input and output real `Tensor`s.
          Default value: None which maps to the default dtype inferred by
          TensorFlow.
        name: Python str. The name to give to the ops created by this class.
          Default value: `None` which maps to 'interest_rate_swap'.
      """
      self._name = name or "interest_rate_swap"
  
      with tf.name_scope(self._name):
          if batch_names is not None:
              self._names = tf.convert_to_tensor(
                  batch_names, name="batch_names"
              )
          else:
              self._names = None
          self._dtype = dtype or tf.float64
  
          self._config = _process_config(config)
          if isinstance(pay_leg, dict):
              self._discount_curve_type = pay_leg["discount_curve_type"]
              self._start_date = start_date
          else:
              currencies = cashflow_streams.to_list(pay_leg.currency)
              self._discount_curve_type = []
              if pay_leg.currency != receive_leg.currency:
                  raise ValueError(
                      "Pay and receive legs should have the same currency"
                  )
              for currency in currencies:
                  if currency in self._config.discounting_curve:
                      discount_curve = self._config.discounting_curve[
                          currency
                      ]
                      self._discount_curve_type.append(discount_curve)
                  else:
                      # Default discounting is the risk free curve
                      risk_free = curve_types_lib.RiskFreeCurve(
                          currency=currency
                      )
                      self._discount_curve_type.append(risk_free)
          if start_date is not None:
              if isinstance(start_date, tf.Tensor):
                  self._start_date = dateslib.dates_from_tensor(
                      start_date
                  )
              else:
                  self._start_date = dateslib.convert_to_date_tensor(
                      start_date
                  )
          else:
              self._start_date = None
          if maturity_date is not None:
              if isinstance(maturity_date, tf.Tensor):
                  self._maturity_date = dateslib.dates_from_tensor(
                      maturity_date
                  )
              else:
                  self._maturity_date = dateslib.convert_to_date_tensor(
                      maturity_date
                  )
          else:
              self._maturity_date = None
          self._pay_leg_schedule_fn = pay_leg_schedule_fn
          self._receive_leg_schedule_fn = receive_leg_schedule_fn
          self._pay_leg_schedule = pay_leg_schedule
          self._receive_leg_schedule = receive_leg_schedule
          self._pay_leg = _setup_leg(
              self._start_date,
              self._maturity_date,
              self._discount_curve_type,
              pay_leg,
              self._pay_leg_schedule_fn,
              self._pay_leg_schedule,
              past_fixing=self._config.past_fixing,
          )
          self._receive_leg = _setup_leg(
              self._start_date,
              self._maturity_date,
              self._discount_curve_type,
              receive_leg,
              self._receive_leg_schedule_fn,
              self._receive_leg_schedule,
              past_fixing=self._config.past_fixing,
          )
          self._batch_shape = self._pay_leg.batch_shape
  
imports: import copy
  from typing import List, Dict, Optional, Union, Any
  import dataclasses
  import tensorflow.compat.v2
  from tf_quant_finance import datetime
  from tf_quant_finance import math
  from tf_quant_finance.experimental.pricing_platform.framework.core import curve_types
  from tf_quant_finance.experimental.pricing_platform.framework.core import instrument
  from tf_quant_finance.experimental.pricing_platform.framework.core import processed_market_data
  from tf_quant_finance.experimental.pricing_platform.framework.core import types
  from tf_quant_finance.experimental.pricing_platform.framework.market_data import utils
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import cashflow_streams
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments import coupon_specs
  from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.interest_rate_swap import proto_utils
  from tf_quant_finance.experimental.pricing_platform.instrument_protos import interest_rate_swap_pb2
label_desc: Use image node_id 1 to create a new InterestRateSwap object from inherited base classes: instrument with example: obj = InterestRateSwap()