<!--
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.heston.approximations.european_option_price" />
<meta itemprop="path" content="Stable" />
</div>

# tf_quant_finance.models.heston.approximations.european_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/heston/approximations/european_option.py">View source</a>



Calculates European option prices under the Heston model.

```python
tf_quant_finance.models.heston.approximations.european_option_price(
    *, strikes, expiries, spots=None, forwards=None, is_call_options=None,
    discount_rates=None, dividend_rates=None, discount_factors=None, variances,
    mean_reversion, theta, volvol, rho=None, integration_method=None, dtype=None,
    name=None, **kwargs
)
```



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

Heston originally published in 1993 his eponymous model [3]. He provided
a semi- analytical formula for pricing European option via Fourier transform
under his model. However, as noted by Albrecher [1], the characteristic
function used in Heston paper can suffer numerical issues because of the
discontinuous nature of the square root function in the complex plane, and a
second version of the characteric function which doesn't suffer this
shortcoming should be used instead. Attari [2] further refined the numerical
method by reducing the number of numerical integrations (only one Fourier
transform instead of two) and with an integrand function decaying
quadratically instead of linearly. Attari's numerical method is implemented
here.

#### Heston model:


```
  dF/F = sqrt(V) * dW_1
  dV = mean_reversion * (theta - V) * dt * sigma * sqrt(V) * dW_2
  <dW_1,dW_2> = rho *dt
```
The variance V follows a square root process.

#### Example
```python
import tf_quant_finance as tff
import numpy as np
prices = tff.models.heston.approximations.european_option_price(
    variances=0.11,
    strikes=102.0,
    expiries=1.2,
    forwards=100.0,
    is_call_options=True,
    mean_reversion=2.0,
    theta=0.5,
    volvol=0.15,
    rho=0.3,
    discount_factors=1.0,
    dtype=np.float64)
# Expected print output of prices:
# 24.82219619
```
#### References
[1] Hansjorg Albrecher, The Little Heston Trap
https://perswww.kuleuven.be/~u0009713/HestonTrap.pdf
[2] Mukarram Attari, Option Pricing Using Fourier Transforms: A Numerically
Efficient Simplification
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=520042
[3] Steven L. Heston, A Closed-Form Solution for Options with Stochastic
Volatility with Applications to Bond and Currency Options
http://faculty.baruch.cuny.edu/lwu/890/Heston93.pdf
Args:
  strikes: A real `Tensor` of any shape and dtype. The strikes of the options
    to be priced.
  expiries: A real `Tensor` of the same dtype and compatible shape as
    `strikes`.  The expiry of each option.
  spots: A real `Tensor` of any shape that broadcasts to the shape of the
    `strikes`. The current spot price of the underlying. Either this
    argument or the `forwards` (but not both) must be supplied.
  forwards: A real `Tensor` of any shape that broadcasts to the shape of
    `strikes`. The forwards to maturity. Either this argument or the
    `spots` must be supplied but both must not be supplied.
  is_call_options: 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.
  discount_rates: An optional real `Tensor` of same dtype as the
    `strikes` and of the shape that broadcasts with `strikes`.
    If not `None`, discount factors are calculated as e^(-rT),
    where r are the discount rates, or risk free rates. At most one of
    discount_rates and discount_factors can be supplied.
    Default value: `None`, equivalent to r = 0 and discount factors = 1 when
    discount_factors also not given.
  dividend_rates: An optional real `Tensor` of same dtype as the
    `strikes` and of the shape that broadcasts with `strikes`.
    Default value: `None`, equivalent to q = 0.
  discount_factors: An optional real `Tensor` of same dtype as the
    `strikes`. If not `None`, these are the discount factors to expiry
    (i.e. e^(-rT)). Mutually exclusive with `discount_rates`. If neither is
    given, no discounting is applied (i.e. the undiscounted option price is
    returned). If `spots` is supplied and `discount_factors` is not `None`
    then this is also used to compute the forwards to expiry. At most one of
    `discount_rates` and `discount_factors` can be supplied.
    Default value: `None`, which maps to e^(-rT) calculated from
    discount_rates.
  variances: A real `Tensor` of the same dtype and compatible shape as
    `strikes`. The initial value of the variance.
  mean_reversion: A real `Tensor` of the same dtype and compatible shape as
    `strikes`. The mean reversion strength of the variance square root
    process.
  theta: A real `Tensor` of the same dtype and compatible shape as
    `strikes`. The mean reversion level of the variance square root process.
  volvol: A real `Tensor` of the same dtype and compatible shape as
    `strikes`. The volatility of the variance square root process (volatility
    of volatility)
  rho: A real `Tensor` of the same dtype and compatible shape as
    `strikes`. The correlation between spot and variance.
  integration_method: An instance of <a href="../../../../tf_quant_finance/math/integration/IntegrationMethod.md"><code>math.integration.IntegrationMethod</code></a>.
    Default value: `None` which maps to the Simpsons integration rule.
  dtype: Optional `tf.DType`. If supplied, the dtype to be used for conversion
    of any supplied non-`Tensor` arguments to `Tensor`.
    Default value: None which maps to the default dtype inferred by
    TensorFlow.
  name: str. The name for the ops created by this function.
    Default value: None which is mapped to the default name
    `heston_price`.
  **kwargs: Additional parameters for the underlying integration method.
    If not supplied and `integration_method` is Simpson, then uses
    <a href="../../../../tf_quant_finance/math/integration/IntegrationMethod.md#COMPOSITE_SIMPSONS_RULE"><code>IntegrationMethod.COMPOSITE_SIMPSONS_RULE</code></a> with `num_points=1001`, and
    bounds `lower=1e-9`, `upper=100`.
Returns:
  A `Tensor` of the same shape as the input data which is the price of
  European options under the Heston model.