code: def equity_leg_cashflows(
      forward_prices,
      spots,
      notional,
      dividends=None,
      dtype=None,
      name=None,
  ):
      """Computes cashflows for a batch of equity legs.
  
      Equity cashflows are defined as a total equity return between pay dates, say,
      `T_1, ..., T_n`. Let `S_i` represent the value of the equity at time `T_i` and
      `d_i` be a discrete dividend paid at this time. Then the the payment at time
      `T_i` is defined as `(S_i - S_{i - 1}) / S_{i-1} + d_i`. The value of
      the cashflow is then the discounted sum of the paments. See, e.g., [1] for the
      reference.
  
      #### Example
      ```python
      notional = 10000
      forward_prices = [[110, 120, 140], [210, 220, 240]]
      spots = [100, 200]
      dividends = [[1, 1, 1], [2, 2, 2]]
      equity_leg_cashflows(forward_prices, spots, notional, dividends,
                           dtype=tf.float64)
      # Expected:
      #  [[1000.01, 909.1, 1666.675],
      #   [ 500.01, 476.2, 909.1]]
      ```
  
      Args:
        forward_prices: A real `Tensor` of shape `batch_shape + [num_cashflows]`,
          where `num_cashflows` is the number of cashflows for each batch element.
          Equity forward prices at leg reset times.
        spots:  A `Tensor` of the same `dtype` as `forward_prices` and of
          shape compatible with `batch_shape`. Spot prices for each batch element
        notional: A `Tensor` of the same `dtype` as `forward_prices` and of
          compatible shape. Notional amount for each cashflow.
        dividends:  A `Tensor` of the same `dtype` as `forward_prices` and of
          compatible shape. Discrete dividends paid at the leg reset times.
          Default value: None which maps to zero dividend.
        dtype: `tf.Dtype`. If supplied the dtype for the input and output `Tensor`s.
          Default value: None which maps to the default dtype inferred from
          `forward_prices`.
        name: Python str. The name to give to the ops created by this function.
          Default value: None which maps to 'equity_leg_cashflows'.
  
      Returns:
        A `Tensor` of the same `dtype` as `forward_prices` and of shape
        `batch_shape + [num_cashflows]`.
  
      #### References
      [1] Don M. Chance and Don R Rich,
        The Pricing of Equity Swaps and Swaptions, 1998
        https://jod.pm-research.com/content/5/4/19
      """
      name = name or "equity_leg_cashflows"
      with tf.name_scope(name):
          forward_prices = tf.convert_to_tensor(
              forward_prices, dtype=dtype, name="forward_prices"
          )
          dtype = dtype or forward_prices.dtype
          spots = tf.convert_to_tensor(spots, dtype=dtype, name="spots")
          notional = tf.convert_to_tensor(
              notional, dtype=dtype, name="notional"
          )
          dividends = 0 if dividends is None else dividends
          dividends = tf.convert_to_tensor(
              dividends, dtype=dtype, name="dividends"
          )
          spots_expand = tf.expand_dims(spots, axis=-1)
          forward_prices = tf.concat(
              [spots_expand, forward_prices], axis=-1
          )
          # Cashflows are equal to
          # (forward_{i+1} - forward_{i} + dividend_{i}) / forward_prices_{i}
          return tf.math.divide_no_nan(
              notional
              * (forward_prices[..., 1:] - forward_prices[..., :-1])
              + dividends,
              forward_prices[..., :-1],
          )
  
file_path: tf-quant-finance/tf_quant_finance/rates/analytics/swap.py
imports: import tensorflow.compat.v2
  from tf_quant_finance.rates.analytics import cashflows
label_desc: Use image node_id 2 for calling a global function with example usage: equity_leg_cashflows(forward_prices, spots, notional, dividends, dtype, name) and returns: tf