S30NCF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentS30NCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

S30NCF computes the European option price given by Heston's stochastic volatility model with term structure.

## 2  Specification

 SUBROUTINE S30NCF ( CALPUT, M, NUMTS, X, FWD, DISC, TS, T, ALPHA, LAMBDA, CORR, SIGMAT, VAR0, P, IFAIL)
 INTEGER M, NUMTS, IFAIL REAL (KIND=nag_wp) X(M), FWD, DISC, TS(NUMTS), T, ALPHA(NUMTS), LAMBDA(NUMTS), CORR(NUMTS), SIGMAT(NUMTS), VAR0, P(M) CHARACTER(1) CALPUT

## 3  Description

S30NCF 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$.
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  Parameters

1:     $\mathrm{CALPUT}$ – CHARACTER(1)Input
On entry: determines whether the option is a call or a put.
${\mathbf{CALPUT}}=\text{'C'}$
A call; the holder has a right to buy.
${\mathbf{CALPUT}}=\text{'P'}$
A put; the holder has a right to sell.
Constraint: ${\mathbf{CALPUT}}=\text{'C'}$ or $\text{'P'}$.
2:     $\mathrm{M}$ – INTEGERInput
On entry: $m$, the number of strike prices to be used.
Constraint: ${\mathbf{M}}\ge 1$.
3:     $\mathrm{NUMTS}$ – INTEGERInput
On entry: ${n}_{s}$, the number of subintervals into which the time to expiry, $T$, is divided.
Constraint: ${\mathbf{NUMTS}}\ge 1$.
4:     $\mathrm{X}\left({\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{X}}\left(i\right)$ contains the $\mathit{i}$th strike price, for $\mathit{i}=1,2,\dots ,m$.
Constraint: ${\mathbf{X}}\left(\mathit{i}\right)\ge z\text{​ and ​}{\mathbf{X}}\left(\mathit{i}\right)\le 1/z$, where $z={\mathbf{X02AMF}}\left(\right)$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{M}}$.
5:     $\mathrm{FWD}$ – REAL (KIND=nag_wp)Input
On entry: the forward price of the asset.
Constraint: ${\mathbf{FWD}}\ge z$ and ${\mathbf{FWD}}\le 1/z$, where $z={\mathbf{X02AMF}}\left(\right)$, the safe range parameter.
6:     $\mathrm{DISC}$ – REAL (KIND=nag_wp)Input
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{X02AMF}}\left(\right)$, the safe range parameter.
7:     $\mathrm{TS}\left({\mathbf{NUMTS}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{TS}}\left(\mathit{i}\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}\right)\ge z\text{​ and ​}{\mathbf{TS}}\left(\mathit{i}\right)\le 1/z$, where $z={\mathbf{X02AMF}}\left(\right)$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{NUMTS}}$.
8:     $\mathrm{T}$ – REAL (KIND=nag_wp)Input
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{X02AMF}}\left(\right)$, the safe range parameter.
9:     $\mathrm{ALPHA}\left({\mathbf{NUMTS}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{ALPHA}}\left(i\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}\right)\ge z\text{​ and ​}{\mathbf{ALPHA}}\left(\mathit{i}\right)\le 1/z$, where $z={\mathbf{X02AMF}}\left(\right)$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{NUMTS}}$.
10:   $\mathrm{LAMBDA}\left({\mathbf{NUMTS}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{LAMBDA}}\left(i\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}\right)\ge z\text{​ and ​}{\mathbf{LAMBDA}}\left(\mathit{i}\right)\le 1/z$, where $z={\mathbf{X02AMF}}\left(\right)$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{NUMTS}}$.
11:   $\mathrm{CORR}\left({\mathbf{NUMTS}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{CORR}}\left(i\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}\right)\le 1.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{NUMTS}}$.
12:   $\mathrm{SIGMAT}\left({\mathbf{NUMTS}}\right)$ – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{SIGMAT}}\left(i\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}\right)\ge z\text{​ and ​}{\mathbf{SIGMAT}}\left(\mathit{i}\right)\le 1/z$, where $z={\mathbf{X02AMF}}\left(\right)$, the safe range parameter, for $\mathit{i}=1,2,\dots ,{\mathbf{NUMTS}}$.
13:   $\mathrm{VAR0}$ – REAL (KIND=nag_wp)Input
On entry: ${\nu }_{0}$, the initial scaled variance.
Constraint: ${\mathbf{VAR0}}\ge 0.0$.
14:   $\mathrm{P}\left({\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{P}}\left(\mathit{i}\right)$ contains the computed option price at the expiry time, $T$, corresponding to strike ${\mathbf{X}}\left(\mathit{i}\right)$ for the specified term structure, for $\mathit{i}=1,2,\dots ,{\mathbf{M}}$.
15:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
On entry, ${\mathbf{CALPUT}}=〈\mathit{\text{value}}〉$ was an illegal value.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{M}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{M}}\ge 1$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{NUMTS}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{NUMTS}}\ge 1$.
${\mathbf{IFAIL}}=4$
On entry, ${\mathbf{X}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{X}}\left(i\right)\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=5$
On entry, ${\mathbf{FWD}}=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{FWD}}\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=6$
On entry, ${\mathbf{DISC}}=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{DISC}}\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=7$
On entry, ${\mathbf{TS}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{TS}}\left(i\right)\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=8$
On entry, ${\mathbf{T}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{T}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=9$
On entry, ${\mathbf{ALPHA}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{ALPHA}}\left(i\right)\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=10$
On entry, ${\mathbf{LAMBDA}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{LAMBDA}}\left(i\right)\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=11$
On entry, ${\mathbf{CORR}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: $\left|{\mathbf{CORR}}\left(i\right)\right|\le 1.0$.
${\mathbf{IFAIL}}=12$
On entry, ${\mathbf{SIGMAT}}\left(〈\mathit{\text{value}}〉\right)=〈\mathit{\text{value}}〉$.
Constraint: $〈\mathit{\text{value}}〉\le {\mathbf{SIGMAT}}\left(i\right)\le 〈\mathit{\text{value}}〉$.
${\mathbf{IFAIL}}=13$
On entry, ${\mathbf{VAR0}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{VAR0}}>0.0$.
${\mathbf{IFAIL}}=14$
Quadrature has not converged to the specified accuracy. However, the result should be a reasonable approximation.
${\mathbf{IFAIL}}=15$
Solution cannot be computed accurately. Check values of input parameters.
${\mathbf{IFAIL}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

## 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

S30NCF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

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 (s30ncfe.f90)

### 10.2  Program Data

Program Data (s30ncfe.d)

### 10.3  Program Results

Program Results (s30ncfe.r)

S30NCF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual