Introduces an example on how to value European options using Heston model in Quantlib Python

Heston model can be used to value options by modeling the underlying asset such as the stock of a company. The one major feature of the Heston model is that it inocrporates a stochastic volatility term.

\begin{eqnarray} dS_t &=& \mu S_tdt + \sqrt{V_t} S_t dW_t^1 \\ dV_t &=& \kappa(\theta-V_t) + \sigma \sqrt{V_t} dW_t^2 \end{eqnarray}

Here :

- $S_t$ is the asset's value at time $t$
- $\mu$ is the expected growth rate of the log normal stock value
- $V_t$ is the variance of the asset $S_t$
- $W_t^1$ is the stochastic process governing the $S_t$ process
- $\theta$ is the value of mean reversion for the variance $V_t$
- $\kappa$ is the strengh of mean reversion
- $\sigma$ is the volatility of volatility
- $W_t^2$ is the stochastic process governing the $V_t$ process
- The correlation between $W_t^1$ and $W_t^2$ is $\rho$

In contrast, the Black-Scholes-Merton process assumes that the volatility is constant.

In [1]:

Expand Code

In [2]:

Expand Code

Using the above inputs, we construct the European option as shown below.

In [3]:

```
# construct the European Option
payoff = ql.PlainVanillaPayoff(option_type, strike_price)
exercise = ql.EuropeanExercise(maturity_date)
european_option = ql.VanillaOption(payoff, exercise)
```

`kappa = 0.1`

, the spot variance `v0 = volatility*volatility = 0.04`

, the mean reversion variance `theta=v0`

, volatility of volatility `sigma = 0.1`

and the correlation between the asset price and its variance is `rho = -0.75`

.

In [4]:

Expand Code

On valuing the option using the Heston model, we get the net present value as:

In [5]:

```
engine = ql.AnalyticHestonEngine(ql.HestonModel(heston_process),0.01, 1000)
european_option.setPricingEngine(engine)
h_price = european_option.NPV()
print "The Heston model price is",h_price
```

Performing the same calculation using the Black-Scholes-Merton process, we get:

In [6]:

Expand Code

`bs_price - h_price = 0.21840667525992163`

. This difference is due to the stochastic modeling of the volatility as a CIR-process.

This post provided a minimal example of valuing European options using the Heston model. Comparison with the Black-Scholes-Merton model is shown for instructional purpose.

quantlib python finance

- QuantLib Python Tutorials With Examples
- On the Convergence of Hull White Monte Carlo Simulations
- Valuing Options on Commodity Futures Using QuantLib Python
- Short Interest Rate Model Calibration in QuantLib Python
- QuantLib Python Cookbook Announcement

I am Goutham Balaraman, and I explore topics in quantitative finance, programming, and data science. You can follow me @gsbalaraman.

Updated posts from this blog and transcripts of Luigi's screencasts on YouTube is compiled into QuantLib Python Cookbook .