<!--
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.black_scholes.swaption_price" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.black_scholes.swaption_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/black_scholes/vanilla_prices.py">View source</a>



Calculates the price of European Swaptions using the Black model.

```python
tf_quant_finance.black_scholes.swaption_price(
    *, volatilities, expiries, floating_leg_start_times, floating_leg_end_times,
    fixed_leg_payment_times, floating_leg_daycount_fractions,
    fixed_leg_daycount_fractions, fixed_leg_coupon,
    floating_leg_start_times_discount_factors,
    floating_leg_end_times_discount_factors,
    fixed_leg_payment_times_discount_factors, notional=None, is_payer_swaption=None,
    is_normal_volatility=True, dtype=None, name=None
)
```



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

A European Swaption is a contract that gives the holder an option to enter a
swap contract at a future date at a prespecified fixed rate. A swaption that
grants the holder to pay fixed rate and receive floating rate is called a
payer swaption while the swaption that grants the holder to receive fixed and
pay floating payments is called the receiver swaption. Typically the start
date (or the inception date) of the swap coincides with the expiry of the
swaption.

#### Example
The example shows how value a batch of 1y x 1y and 1y x 2y swaptions using the
Black (normal) model for the swap rate.

````python
import numpy as np
import tensorflow as tf
import tf_quant_finance as tff

dtype = tf.float64

volatilities = [0.01, 0.005]
expiries = [1.0, 1.0]
float_leg_start_times = [[1.0, 1.25, 1.5, 1.75, 2.0, 2.0, 2.0, 2.0],
                          [1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75]]
float_leg_end_times = [[1.25, 1.5, 1.75, 2.0, 2.0, 2.0, 2.0, 2.0],
                        [1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]]
fixed_leg_payment_times = [[1.25, 1.5, 1.75, 2.0, 2.0, 2.0, 2.0, 2.0],
                            [1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0]]
float_leg_daycount_fractions = [[0.25, 0.25, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0],
                                 [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
                                 0.25]]
fixed_leg_daycount_fractions = [[0.25, 0.25, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0],
                                 [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
                                 0.25]]
fixed_leg_coupon = [0.011, 0.011]
discount_fn = lambda x: np.exp(-0.01 * np.array(x))
price = self.evaluate(
tff.black_scholes.swaption_price(
    volatilities=volatilities,
    expiries=expiries,
    floating_leg_start_times=float_leg_start_times,
    floating_leg_end_times=float_leg_end_times,
    fixed_leg_payment_times=fixed_leg_payment_times,
    floating_leg_daycount_fractions=float_leg_daycount_fractions,
    fixed_leg_daycount_fractions=fixed_leg_daycount_fractions,
    fixed_leg_coupon=fixed_leg_coupon,
    floating_leg_start_times_discount_factors=discount_fn(
        float_leg_start_times),
    floating_leg_end_times_discount_factors=discount_fn(
        float_leg_end_times),
    fixed_leg_payment_times_discount_factors=discount_fn(
        fixed_leg_payment_times),
    is_normal_volatility=is_normal_model,
    notional=100.,
    dtype=dtype))
# Expected value: [0.3458467885511461, 0.3014786656395892] # shape = (2,)
````

#### Args:


* <b>`volatilities`</b>: Real `Tensor` of any shape and dtype. The Black volatilities
  of the swaptions to price. The shape of this input determines the number
  (and shape) of swaptions to be priced and the shape of the output.
* <b>`expiries`</b>: A real `Tensor` of same shape and dtype as `volatilities`. The
  time to expiration of the swaptions.
* <b>`floating_leg_start_times`</b>: A real `Tensor` of the same dtype as
  `volatilities`. The times when accrual begins for each payment in the
  floating leg. The shape of this input should be `expiries.shape + [m]` or
  `batch_shape + [m]` where `m` denotes the number of floating payments in
  each leg.
* <b>`floating_leg_end_times`</b>: A real `Tensor` of the same dtype as `volatilities`.
  The times when accrual ends for each payment in the floating leg. The
  shape of this input should be `batch_shape + [m]` where `m` denotes
  the number of floating payments in each leg.
* <b>`fixed_leg_payment_times`</b>: A real `Tensor` of the same dtype as
  `volatilities`.  The payment times for each payment in the fixed leg.
  The shape of this input should be `batch_shape + [n]` where `n` denotes
  the number of fixed payments in each leg.
* <b>`floating_leg_daycount_fractions`</b>: A real `Tensor` of the same dtype and
  compatible shape as `floating_leg_start_times`. The daycount fractions
  for each payment in the floating leg.
* <b>`fixed_leg_daycount_fractions`</b>: A real `Tensor` of the same dtype and
  compatible shape as `fixed_leg_payment_times`. The daycount fractions
  for each payment in the fixed leg.
* <b>`fixed_leg_coupon`</b>: A real `Tensor` of the same dtype and shape compatible
  to `batch_shape`. The fixed coupon rate for each payment in the fixed leg.
* <b>`floating_leg_start_times_discount_factors`</b>: A real `Tensor` of the same
  shape and dtype as `floating_leg_start_times`. The discount factors
  corresponding to `floating_leg_start_times`.
* <b>`floating_leg_end_times_discount_factors`</b>: A real `Tensor` of the same
  shape and dtype as `floating_leg_end_times`. The discount factors
  corresponding to `floating_leg_end_times`.
* <b>`fixed_leg_payment_times_discount_factors`</b>: A real `Tensor` of the same
  shape and dtype as `fixed_leg_payment_times`. The discount factors
  corresponding to `fixed_leg_payment_times`.
* <b>`notional`</b>: An optional `Tensor` of same dtype and compatible shape as
  `volatilities` specifying the notional amount for the underlying swap.
   Default value: None in which case the notional is set to 1.
* <b>`is_payer_swaption`</b>: A boolean `Tensor` of a shape compatible with `expiries`.
  Indicates whether the swaption is a payer (if True) or a receiver
  (if False) swaption. If not supplied, payer swaptions are assumed.
* <b>`is_normal_volatility`</b>: An optional Python boolean specifying whether the
  `volatilities` correspond to normal Black volatility (if True) or
  lognormal Black volatility (if False).
  Default value: True, which corresponds to normal volatility.
* <b>`dtype`</b>: The default dtype to use when converting values to `Tensor`s.
  Default value: `None` which means that default dtypes inferred by
  TensorFlow are used.
* <b>`name`</b>: Python string. The name to give to the ops created by this function.
  Default value: `None` which maps to the default name
  `hw_swaption_price`.


#### Returns:

A `Tensor` of real dtype and shape `batch_shape` containing the
computed swaption prices.
