<!--
This file is generated by a tool. Do not edit directly.
For open-source contributions the docs will be updated automatically.
-->

*Last updated: 2023-03-16.*

<div itemscope itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="tf_quant_finance.rates.analytics.swap.swap_price" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.rates.analytics.swap.swap_price

<!-- Insert buttons and diff -->

<table class="tfo-notebook-buttons tfo-api" align="left">
</table>

<a target="_blank" href="https://github.com/paolodelia99/tf-quant-finance/blob/main/tf_quant_finance/rates/analytics/swap.py">View source</a>



Computes prices of a batch of generic swaps.

```python
tf_quant_finance.rates.analytics.swap.swap_price(
    pay_leg_cashflows, receive_leg_cashflows, pay_leg_discount_factors,
    receive_leg_discount_factors, dtype=None, name=None
)
```



<!-- Placeholder for "Used in" -->

#### Example
```python
pay_leg_cashflows = [[100, 100, 100], [200, 250, 300]]
receive_leg_cashflows = [[200, 250, 300, 300], [100, 100, 100, 100]]
pay_leg_discount_factors = [[0.95, 0.9, 0.8],
                            [0.9, 0.85, 0.8]]
receive_leg_discount_factors = [[0.95, 0.9, 0.8, 0.75],
                                [0.9, 0.85, 0.8, 0.75]]
swap_price(pay_leg_cashflows=pay_leg_cashflows,
           receive_leg_cashflows=receive_leg_cashflows,
           pay_leg_discount_factors=pay_leg_discount_factors,
           receive_leg_discount_factors=receive_leg_discount_factors,
           dtype=tf.float64)
# Expected: [615.0, -302.5]
```

#### Args:


* <b>`pay_leg_cashflows`</b>: A real `Tensor` of shape
  `batch_shape + [num_pay_cashflows]`, where `num_pay_cashflows` is the
  number of cashflows for each batch element. Cashflows of the pay leg of
  the swaps.
* <b>`receive_leg_cashflows`</b>: A `Tensor` of the same `dtype` as `pay_leg_cashflows`
  and of shape `batch_shape + [num_receive_cashflows]` where
  `num_pay_cashflows` is the number of cashflows for each batch element.
  Cashflows of the receive leg of the swaps.
* <b>`pay_leg_discount_factors`</b>: A `Tensor` of the same `dtype` as
  `pay_leg_cashflows` and of compatible shape. Discount factors for each
  cashflow of the pay leg.
* <b>`receive_leg_discount_factors`</b>: A `Tensor` of the same `dtype` as
  `receive_leg_cashflows` and of compatible shape. Discount factors for each
  cashflow of the receive leg.
* <b>`dtype`</b>: `tf.Dtype`. If supplied the dtype for the input and output `Tensor`s.
  Default value: None which maps to the default dtype inferred from
  `pay_leg_cashflows`.
* <b>`name`</b>: Python str. The name to give to the ops created by this function.
  Default value: None which maps to 'floating_coupons'.


#### Returns:

A `Tensor` of the same `dtype` as `coupon_rates` and of shape `batch_shape`.
Present values of swaps from receiver perspective.
