<!--
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.models.hjm.bond_option_price" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.models.hjm.bond_option_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/models/hjm/zero_coupon_bond_option.py">View source</a>



Calculates European bond option prices using the HJM model.

```python
tf_quant_finance.models.hjm.bond_option_price(
    *, strikes, expiries, maturities, discount_rate_fn, dim, mean_reversion,
    volatility, corr_matrix=None, is_call_options=True, num_samples=1,
    random_type=None, seed=None, skip=0, time_step=None, dtype=None, name=None
)
```



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

Bond options are fixed income securities which give the holder a right to
exchange at a future date (the option expiry) a zero coupon bond for a fixed
price (the strike of the option). The maturity date of the bond is after the
the expiry of the option. If `P(t,T)` denotes the price at time `t` of a zero
coupon bond with maturity `T`, then the payoff from the option at option
expiry, `T0`, is given by:

```None
payoff = max(P(T0, T) - X, 0)
```
where `X` is the strike price of the option.

#### Example

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

dtype = tf.float64

discount_rate_fn = lambda x: 0.01 * tf.ones_like(x, dtype=dtype)
expiries = np.array([1.0])
maturities = np.array([5.0])
strikes = np.exp(-0.01 * maturities) / np.exp(-0.01 * expiries)
price = tff.models.hjm.bond_option_price(
    strikes=strikes,
    expiries=expiries,
    maturities=maturities,
    dim=1,
    mean_reversion=[0.03],
    volatility=[0.02],
    discount_rate_fn=discount_rate_fn,
    dtype=dtype)
# Expected value: [[0.02817777]]
````

#### Args:


* <b>`strikes`</b>: A real `Tensor` of any shape and dtype. The strike price of the
  options. The shape of this input determines the number (and shape) of the
  options to be priced and the output.
* <b>`expiries`</b>: A real `Tensor` of the same dtype and compatible shape as
  `strikes`.  The time to expiry of each bond option.
* <b>`maturities`</b>: A real `Tensor` of the same dtype and compatible shape as
  `strikes`.  The time to maturity of the underlying zero coupon bonds.
* <b>`discount_rate_fn`</b>: A Python callable that accepts expiry time as a real
  `Tensor` and returns a `Tensor` of shape `input_shape`. Computes the
  zero coupon bond yield at the present time for the input expiry time.
* <b>`dim`</b>: A Python scalar which corresponds to the number of factors within a
  single HJM model.
* <b>`mean_reversion`</b>: A real positive `Tensor` of shape `[dim]`. Corresponds to
  the mean reversion rate of each factor.
* <b>`volatility`</b>: A real positive `Tensor` of the same `dtype` and shape as
  `mean_reversion` or a callable with the following properties: (a)  The
    callable should accept a scalar `Tensor` `t` and a 1-D `Tensor` `r(t)`
    of shape `[num_samples]` and returns a 2-D `Tensor` of shape
    `[num_samples, dim]`. The variable `t`  stands for time and `r(t)` is
    the short rate at time `t`.  The function returns instantaneous
    volatility `sigma(t) = sigma(t, r(t))`. When `volatility` is specified
    is a real `Tensor`, each factor is assumed to have a constant
    instantaneous volatility  and the  model is effectively a Gaussian HJM
    model. Corresponds to the instantaneous volatility of each factor.
* <b>`corr_matrix`</b>: A `Tensor` of shape `[dim, dim]` and the same `dtype` as
  `mean_reversion`. Corresponds to the correlation matrix `Rho`.
  Default value: None, meaning the factors are uncorrelated.
* <b>`is_call_options`</b>: A boolean `Tensor` of a shape compatible with `strikes`.
  Indicates whether the option is a call (if True) or a put (if False). If
  not supplied, call options are assumed.
* <b>`num_samples`</b>: Positive scalar `int32` `Tensor`. The number of simulation
  paths during Monte-Carlo valuation.
  Default value: The default value is 1.
* <b>`random_type`</b>: Enum value of `RandomType`. The type of (quasi)-random number
  generator to use to generate the simulation paths.
  Default value: `None` which maps to the standard pseudo-random numbers.
* <b>`seed`</b>: Seed for the random number generator. The seed is only relevant if
  `random_type` is one of `[STATELESS, PSEUDO, HALTON_RANDOMIZED,
  PSEUDO_ANTITHETIC, STATELESS_ANTITHETIC]`. For `PSEUDO`,
  `PSEUDO_ANTITHETIC` and `HALTON_RANDOMIZED` the seed should be an Python
  integer. For `STATELESS` and  `STATELESS_ANTITHETIC `must be supplied as
  an integer `Tensor` of shape `[2]`.
  Default value: `None` which means no seed is set.
* <b>`skip`</b>: `int32` 0-d `Tensor`. The number of initial points of the Sobol or
  Halton sequence to skip. Used only when `random_type` is 'SOBOL',
  'HALTON', or 'HALTON_RANDOMIZED', otherwise ignored.
  Default value: `0`.
* <b>`time_step`</b>: Scalar real `Tensor`. Maximal distance between time grid points
  in Euler scheme. Relevant when Euler scheme is used for simulation.
  Default value: `None`.
* <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 class.
  Default value: `None` which maps to the default name
    `hw_bond_option_price`.


#### Returns:

A `Tensor` of real dtype and shape  `strikes.shape` containing the
computed option prices.
