s Chapter Contents
s Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_heston_term (s30ncc)

## 1  Purpose

nag_heston_term (s30ncc) computes the European option price given by Heston's stochastic volatility model with term structure.

## 2  Specification

 #include #include
 void nag_heston_term (Nag_CallPut option, Integer m, Integer numts, const double x[], double fwd, double disc, const double ts[], double t, const double alpha[], const double lambda[], const double corr[], const double sigmat[], double var0, double p[], NagError *fail)

## 3  Description

nag_heston_term (s30ncc) computes the price of a European option for Heston's stochastic volatility model with time-dependent parameters which are piecewise constant. Starting from the stochastic volatility model given by the Stochastic Differential Equation (SDE) system defined by Heston (1993), a scaling of the variance process is introduced, together with a normalization, setting the long run variance, $\eta$, equal to $1$. This leads to
 $d St St = μt d t+σt νt d Wt1 ,$ (1)
 $d νt = λt 1-νt d t+ αt νt d Wt2 ,$ (2)
 $Cov d W t 1 , d W t 2 = ρt d t ,$ (3)
where ${\mu }_{t}={r}_{t}-{q}_{t}$ is the drift term representing the contribution of interest rates, ${r}_{t}$, and dividends, ${q}_{t}$, while ${\sigma }_{t}$ is the scaling parameter, ${\nu }_{t}$ is the scaled variance, ${\lambda }_{t}$ is the mean reversion rate and ${\alpha }_{t}$ is the volatility of the scaled volatility, $\sqrt{{\nu }_{t}}$. Then, ${W}_{t}^{\left(\mathit{i}\right)}$, for $\mathit{i}=1,2$, are two standard Brownian motions with correlation parameter ${\rho }_{t}$. Without loss of generality, the drift term, ${\mu }_{t}$, is eliminated by modelling the forward price, ${F}_{t}$, directly, instead of the spot price, ${S}_{t}$, with
 $Ft = S0 exp ∫ 0 t μs d s .$ (4)
If required, the spot can be expressed as, ${S}_{0}=D{F}_{t}$, where $D$ is the discount factor.
The option price is computed by dividing the time to expiry, $T$, into ${n}_{s}$ subintervals $\left[{t}_{0},{t}_{1}\right],\dots ,\left[{t}_{i-1},{t}_{i}\right],\dots ,\left[{t}_{{n}_{s}-1},T\right]$ and applying the method of characteristic functions to each subinterval, with appropriate initial conditions. Thus, a pair of ordinary differential equations (one of which is a Riccati equation) is solved on each subinterval as outlined in Elices (2008) and Mikhailov and Nögel (2003). Reversing time by taking $\tau =T-t$, the characteristic function solution for the first time subinterval, starting at $\tau =0$, is given by Heston (1993), while the solution on each following subinterval uses the solution of the preceding subinterval as initial condition to compute the value of the characteristic function.
In the case of a ‘flat’ term structure, i.e., the parameters are constant over the time of the option, $T$, the form of the SDE system given by Heston (1993)
 $d St St = μt d t+ Vt d W t 1 ,$ (5)
 $d Vt = κ η-Vt d t + σv Vt d W t 2 ,$ (6)
can be recovered by setting ${V}_{0}=\eta ={\sigma }_{t}^{2}$, $\kappa ={\lambda }_{t}$, ${\sigma }_{v}={\sigma }_{t}{\alpha }_{t}$.
Conversely, given the Heston form of the SDE pair, to get the term structure form set $\sigma =\sqrt{\eta }$, ${\alpha }_{t}={\sigma }_{v}/\sqrt{\eta }$, ${\lambda }_{t}=\kappa$.

## 4  References

Bain A (2011) Private communication
Elices A (2008) Models with time-dependent parameters using transform methods: application to Heston’s model arXiv:0708.2020v2
Heston S (1993) A closed-form solution for options with stochastic volatility with applications to bond and currency options Review of Financial Studies 6 327–343
Mikhailov S and Nögel U (2003) Heston’s Stochastic Volatility Model Implementation, Calibration and Some Extensions Wilmott Magazine July/August 74–79

## 5  Arguments

1:     optionNag_CallPutInput
On entry: determines whether the option is a call or a put.
${\mathbf{option}}=\mathrm{Nag_Call}$
A call; the holder has a right to buy.
${\mathbf{option}}=\mathrm{Nag_Put}$
A put; the holder has a right to sell.
Constraint: ${\mathbf{option}}=\mathrm{Nag_Call}$ or $\mathrm{Nag_Put}$.
2:     mIntegerInput
On entry: $m$, the number of strike prices to be used.
Constraint: ${\mathbf{m}}\ge 1$.
3:     numtsIntegerInput
On entry: ${n}_{s}$, the number of subintervals into which the time to expiry, $T$, is divided.
Constraint: ${\mathbf{numts}}\ge 1$.
4:     x[m]const doubleInput
On entry: ${\mathbf{x}}\left[i-1\right]$ contains the $\mathit{i}$th strike price, for $\mathit{i}=1,2,\dots ,m$.
Constraint: ${\mathbf{x}}\left[\mathit{i}-1\right]\ge z\text{​ and ​}{\mathbf{x}}\left[\mathit{i}-1\right]\le 1/z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
5:     fwddoubleInput
On entry: the forward price of the asset.
Constraint: ${\mathbf{fwd}}\ge z$ and ${\mathbf{fwd}}\le 1/z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter.
6:     discdoubleInput
On entry: the discount factor, where the current price of the underlying asset, ${S}_{0}$, is given as ${S}_{0}={\mathbf{disc}}×{\mathbf{fwd}}$.
Constraint: ${\mathbf{disc}}\ge z$ and ${\mathbf{disc}}\le 1/z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter.
7:     ts[numts]const doubleInput
On entry: ${\mathbf{ts}}\left[\mathit{i}-1\right]$ must contain the length of the time intervals for which the corresponding element of alpha, lambda, corr and sigmat apply. These should be ordered as they occur in time i.e., $\Delta {t}_{\mathit{i}}={t}_{\mathit{i}}-{t}_{\mathit{i}-1}$.
Constraint: ${\mathbf{ts}}\left[\mathit{i}-1\right]\ge z\text{​ and ​}{\mathbf{ts}}\left[\mathit{i}-1\right]\le 1/z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{numts}}$.
8:     tdoubleInput
On entry: t contains the time to expiry. If $T>\sum \Delta {t}_{\mathit{i}}$ then the parameters associated with the last time interval are extended to the expiry time. If $T<\sum \Delta {t}_{\mathit{i}}$ then the parameters specified are used up until the expiry time. The rest are ignored.
Constraint: ${\mathbf{t}}\ge z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter.
9:     alpha[numts]const doubleInput
On entry: ${\mathbf{alpha}}\left[i-1\right]$ must contain the value of ${\alpha }_{t}$, the value of the volatility of the scaled volatility, $\sqrt{\nu }$, over time subinterval $\Delta {t}_{i}$.
Constraint: ${\mathbf{alpha}}\left[\mathit{i}-1\right]\ge z\text{​ and ​}{\mathbf{alpha}}\left[\mathit{i}-1\right]\le 1/z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{numts}}$.
10:   lambda[numts]const doubleInput
On entry: ${\mathbf{lambda}}\left[i-1\right]$ must contain the value, ${\lambda }_{t}$, of the mean reversion parameter over the time subinterval $\Delta {t}_{i}$.
Constraint: ${\mathbf{lambda}}\left[\mathit{i}-1\right]\ge z\text{​ and ​}{\mathbf{lambda}}\left[\mathit{i}-1\right]\le 1/z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{numts}}$.
11:   corr[numts]const doubleInput
On entry: ${\mathbf{corr}}\left[i-1\right]$ must contain the value, ${\rho }_{t}$, of the correlation parameter over the time subinterval $\Delta {t}_{i}$.
Constraint: $-1.0\le {\mathbf{corr}}\left[\mathit{i}-1\right]\le 1.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{numts}}$.
12:   sigmat[numts]const doubleInput
On entry: ${\mathbf{sigmat}}\left[i-1\right]$ must contain the value, ${\sigma }_{t}$, of the variance scale factor over the time subinterval $\Delta {t}_{i}$.
Constraint: ${\mathbf{sigmat}}\left[\mathit{i}-1\right]\ge z\text{​ and ​}{\mathbf{sigmat}}\left[\mathit{i}-1\right]\le 1/z$, where $z={\mathbf{nag_real_safe_small_number}}$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{numts}}$.
13:   var0doubleInput
On entry: ${\nu }_{0}$, the initial scaled variance.
Constraint: ${\mathbf{var0}}\ge 0.0$.
14:   p[m]doubleOutput
On exit: ${\mathbf{p}}\left[\mathit{i}-1\right]$ contains the computed option price at the expiry time, $T$, corresponding to strike ${\mathbf{x}}\left[\mathit{i}-1\right]$ for the specified term structure, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
15:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ACCURACY
Solution cannot be computed accurately. Check values of input arguments.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_CONVERGENCE
Quadrature has not converged to the specified accuracy. However, the result should be a reasonable approximation.
NE_INT
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{numts}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{numts}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL
On entry, ${\mathbf{disc}}=⟨\mathit{\text{value}}⟩$.
Constraint: $⟨\mathit{\text{value}}⟩\le {\mathbf{disc}}\le ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{fwd}}=⟨\mathit{\text{value}}⟩$.
Constraint: $⟨\mathit{\text{value}}⟩\le {\mathbf{fwd}}\le ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{t}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{t}}\ge ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{var0}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{var0}}>0.0$.
NE_REAL_ARRAY
On entry, ${\mathbf{alpha}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $⟨\mathit{\text{value}}⟩\le {\mathbf{alpha}}\left[i-1\right]\le ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{corr}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $\left|{\mathbf{corr}}\left[i-1\right]\right|\le 1.0$.
On entry, ${\mathbf{lambda}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $⟨\mathit{\text{value}}⟩\le {\mathbf{lambda}}\left[i-1\right]\le ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{sigmat}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $⟨\mathit{\text{value}}⟩\le {\mathbf{sigmat}}\left[i-1\right]\le ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{ts}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $⟨\mathit{\text{value}}⟩\le {\mathbf{ts}}\left[i-1\right]\le ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{x}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: $⟨\mathit{\text{value}}⟩\le {\mathbf{x}}\left[i-1\right]\le ⟨\mathit{\text{value}}⟩$.

## 7  Accuracy

The solution is obtained by integrating the pair of ordinary differential equations over each subinterval in time. The accuracy is controlled by a relative tolerance over each time subinterval, which is set to ${10}^{-8}$. Over a number of subintervals in time the error may accumulate and so the overall error in the computation may be greater than this. A threshold of ${10}^{-10}$ is used and solutions smaller than this are not accurately evaluated.

## 8  Parallelism and Performance

nag_heston_term (s30ncc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.

None.

## 10  Example

This example computes the price of a European call using Heston's stochastic volatility model with a term structure of interest rates.

### 10.1  Program Text

Program Text (s30ncce.c)

### 10.2  Program Data

Program Data (s30ncce.d)

### 10.3  Program Results

Program Results (s30ncce.r)