nag_pde_bs_1d_analytic (d03ndc) (PDF version)
d03 Chapter Contents
d03 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_pde_bs_1d_analytic (d03ndc)

## 1  Purpose

nag_pde_bs_1d_analytic (d03ndc) computes an analytic solution to the Black–Scholes equation for a certain set of option types.

## 2  Specification

 #include #include
 void nag_pde_bs_1d_analytic (Nag_OptionType kopt, double x, double s, double t, double tmat, const Nag_Boolean tdpar[], const double r[], const double q[], const double sigma[], double *f, double *theta, double *delta, double *gamma, double *lambda, double *rho, NagError *fail)

## 3  Description

nag_pde_bs_1d_analytic (d03ndc) computes an analytic solution to the Black–Scholes equation (see Hull (1989) and Wilmott et al. (1995))
 $∂f ∂t + r-q S ∂f ∂S + σ2 S2 2 ∂2f ∂S2 =rf$ (1)
 $Smin< S (2)
for the value $f$ of a European put or call option, or an American call option with zero dividend $q$. In equation (1) $t$ is time, $S$ is the stock price, $X$ is the exercise price, $r$ is the risk free interest rate, $q$ is the continuous dividend, and $\sigma$ is the stock volatility. The arguments $r$, $q$ and $\sigma$ may be either constant, or functions of time. In the latter case their average instantaneous values over the remaining life of the option should be provided to nag_pde_bs_1d_analytic (d03ndc). An auxiliary function nag_pde_bs_1d_means (d03nec) is available to compute such averages from values at a set of discrete times.
nag_pde_bs_1d_analytic (d03ndc) also returns values of the Greeks
 $Θ= ∂f ∂t , Δ= ∂f ∂x , Γ= ∂2f ∂x2 , Λ= ∂f ∂σ , ρ= ∂f ∂r .$
nag_bsm_greeks (s30abc) also computes the European option price given by the Black–Scholes–Merton formula together with a more comprehensive set of sensitivities (Greeks).
Further details of the analytic solution returned are given in Section 8.1.

## 4  References

Hull J (1989) Options, Futures and Other Derivative Securities Prentice–Hall
Wilmott P, Howison S and Dewynne J (1995) The Mathematics of Financial Derivatives Cambridge University Press

## 5  Arguments

1:     koptNag_OptionTypeInput
On entry: specifies the kind of option to be valued:
${\mathbf{kopt}}=\mathrm{Nag_EuropeanCall}$
A European call option.
${\mathbf{kopt}}=\mathrm{Nag_AmericanCall}$
An American call option.
${\mathbf{kopt}}=\mathrm{Nag_EuropeanPut}$
A European put option.
Constraints:
• ${\mathbf{kopt}}=\mathrm{Nag_EuropeanCall}$, $\mathrm{Nag_AmericanCall}$ or $\mathrm{Nag_EuropeanPut}$;
• if $q\ne 0$, ${\mathbf{kopt}}\ne \mathrm{Nag_AmericanCall}$.
2:     xdoubleInput
On entry: the exercise price $X$.
Constraint: ${\mathbf{x}}\ge 0.0$.
3:     sdoubleInput
On entry: the stock price at which the option value and the Greeks should be evaluated.
Constraint: ${\mathbf{s}}\ge 0.0$.
4:     tdoubleInput
On entry: the time at which the option value and the Greeks should be evaluated.
Constraint: ${\mathbf{t}}\ge 0.0$.
5:     tmatdoubleInput
On entry: the maturity time of the option.
Constraint: ${\mathbf{tmat}}\ge {\mathbf{t}}$.
6:     tdpar[$3$]const Nag_BooleanInput
On entry: specifies whether or not various arguments are time-dependent. More precisely, $r$ is time-dependent if ${\mathbf{tdpar}}\left[0\right]=\mathrm{Nag_TRUE}$ and constant otherwise. Similarly, ${\mathbf{tdpar}}\left[1\right]$ specifies whether $q$ is time-dependent and ${\mathbf{tdpar}}\left[2\right]$ specifies whether $\sigma$ is time-dependent.
7:     r[$\mathit{dim}$]const doubleInput
Note: the dimension, dim, of the array r must be at least
• $3$ when ${\mathbf{tdpar}}\left[0\right]=\mathrm{Nag_TRUE}$;
• $1$ otherwise.
On entry: if ${\mathbf{tdpar}}\left[0\right]=\mathrm{Nag_FALSE}$ then ${\mathbf{r}}\left[0\right]$ must contain the constant value of $r$. The remaining elements need not be set.
If ${\mathbf{tdpar}}\left[0\right]=\mathrm{Nag_TRUE}$ then ${\mathbf{r}}\left[0\right]$ must contain the value of $r$ at time t and ${\mathbf{r}}\left[1\right]$ must contain its average instantaneous value over the remaining life of the option:
 $r^=∫ttmatrζdζ.$
The auxiliary function nag_pde_bs_1d_means (d03nec) may be used to construct r from a set of values of $r$ at discrete times.
8:     q[$\mathit{dim}$]const doubleInput
Note: the dimension, dim, of the array q must be at least
• $3$ when ${\mathbf{tdpar}}\left[1\right]=\mathrm{Nag_TRUE}$;
• $1$ otherwise.
On entry: if ${\mathbf{tdpar}}\left[1\right]=\mathrm{Nag_FALSE}$ then ${\mathbf{q}}\left[0\right]$ must contain the constant value of $q$. The remaining elements need not be set.
If ${\mathbf{tdpar}}\left[1\right]=\mathrm{Nag_TRUE}$ then ${\mathbf{q}}\left[0\right]$ must contain the constant value of $q$ and ${\mathbf{q}}\left[1\right]$ must contain its average instantaneous value over the remaining life of the option:
 $q^=∫ttmatqζdζ.$
The auxiliary function nag_pde_bs_1d_means (d03nec) may be used to construct q from a set of values of $q$ at discrete times.
9:     sigma[$\mathit{dim}$]const doubleInput
Note: the dimension, dim, of the array sigma must be at least
• $3$ when ${\mathbf{tdpar}}\left[2\right]=\mathrm{Nag_TRUE}$;
• $1$ otherwise.
On entry: if ${\mathbf{tdpar}}\left[2\right]=\mathrm{Nag_FALSE}$ then ${\mathbf{sigma}}\left[0\right]$ must contain the constant value of $\sigma$. The remaining elements need not be set.
If ${\mathbf{tdpar}}\left[2\right]=\mathrm{Nag_TRUE}$ then ${\mathbf{sigma}}\left[0\right]$ must contain the value of $\sigma$ at time t, ${\mathbf{sigma}}\left[1\right]$ the average instantaneous value $\stackrel{^}{\sigma }$, and ${\mathbf{sigma}}\left[2\right]$ the second-order average $\stackrel{-}{\sigma }$, where:
 $σ^=∫ttmatσζdζ,$
 $σ-= ∫ttmat σ2 ζ dζ 1/2 .$
The auxiliary function nag_pde_bs_1d_means (d03nec) may be used to compute sigma from a set of values at discrete times.
Constraints:
• if ${\mathbf{tdpar}}\left[2\right]=\mathrm{Nag_FALSE}$, ${\mathbf{sigma}}\left[0\right]>0.0$;
• if ${\mathbf{tdpar}}\left[2\right]=\mathrm{Nag_TRUE}$, ${\mathbf{sigma}}\left[\mathit{i}-1\right]>0.0$, for $\mathit{i}=1,2,3$.
10:   fdouble *Output
On exit: the value $f$ of the option at the stock price s and time t.
11:   thetadouble *Output
12:   deltadouble *Output
13:   gammadouble *Output
14:   lambdadouble *Output
15:   rhodouble *Output
On exit: the values of various Greeks at the stock price s and time t, as follows:
 $theta=Θ= ∂f ∂t , delta=Δ= ∂f ∂s , gamma=Γ= ∂2f ∂s2 , lambda=Λ= ∂f ∂σ , rho=ρ= ∂f ∂r .$
16:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_BAD_PARAM
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INCOMPAT_PARAM
On entry, ${\mathbf{q}}\left[0\right]$ is not equal to $0.0$ with American call option. ${\mathbf{q}}\left[0\right]=〈\mathit{\text{value}}〉$.
On entry, ${\mathbf{sigma}}\left[i-1\right]=〈\mathit{\text{value}}〉$ and $i=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{sigma}}\left[i-1\right]>0.0$.
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{s}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{s}}\ge 0.0$.
On entry, ${\mathbf{t}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{t}}\ge 0.0$.
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\ge 0.0$.
NE_REAL_2
On entry, ${\mathbf{tmat}}=〈\mathit{\text{value}}〉$ and ${\mathbf{t}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{tmat}}\ge {\mathbf{t}}$.

## 7  Accuracy

Given accurate values of r, q and sigma no further approximations are made in the evaluation of the Black–Scholes analytic formulae, and the results should therefore be within machine accuracy. The values of r, q and sigma returned from nag_pde_bs_1d_means (d03nec) are exact for polynomials of degree up to $3$.

## 8  Further Comments

### 8.1  Algorithmic Details

The Black–Scholes analytic formulae are used to compute the solution. For a European call option these are as follows:
 $f= S e -q^ T-t N d1- X e -r^ T-t Nd2$
where
 $d1 = logS/X+r^-q^+σ-2/2T-t σ-T-t , d2 = logS/X+r^-q^-σ-2/2T-t σ-T-t =d1-σ-T-t,$
$N\left(x\right)$ is the cumulative Normal distribution function and ${N}^{\prime }\left(x\right)$ is its derivative
 $Nx = 12π ∫-∞x e-ζ2/2dζ, N′x = 12π e-x2/2.$
The functions $\stackrel{^}{q}$, $\stackrel{^}{r}$, $\stackrel{^}{\sigma }$ and $\stackrel{-}{\sigma }$ are average values of $q$, $r$ and $\sigma$ over the time to maturity:
 $q^ = 1T-t ∫tT qζdζ, r^ = 1T-t ∫tT rζdζ, σ^ = 1T-t ∫tT σζdζ, σ- = 1T-t ∫tT σ2ζdζ 1/2 .$
The Greeks are then calculated as follows:
 $Δ = ∂f ∂S =e-q^T-t Nd1+ Se-q^T-t N′d1-Xe-r^T-t N′d2 σ-S⁢T-t , Γ = ∂2 f ∂S2 = Se-q^T-t N′d1+Xe-r^T-t N′d2 σ-S2T-t + Se-q^T-t N′d1-Xe-r^T-t N′d2 σ-2S2T-t , Θ = ∂f ∂t =rf+q-r SΔ- σ2 S22Γ, Λ = ∂f ∂σ = X d1 e-r^T-t N′d2-S d2 e-q^T-t N′d1 σ-2 σ^, ρ = ∂f ∂r =XT-t e-r^T-t Nd2+ Se-q^T-t N′d1-Xe-r^T-t N′d2 T-tσ-.$
Note: that $\Theta$ is obtained from substitution of other Greeks in the Black–Scholes partial differential equation, rather than differentiation of $f$. The values of $q$, $r$ and $\sigma$ appearing in its definition are the instantaneous values, not the averages. Note also that both the first-order average $\stackrel{^}{\sigma }$ and the second-order average $\stackrel{-}{\sigma }$ appear in the expression for $\Lambda$. This results from the fact that $\Lambda$ is the derivative of $f$ with respect to $\sigma$, not $\stackrel{^}{\sigma }$.
For a European put option the equivalent equations are:
 $f = Xe-r^T-t N-d2-Se-q^T-t N-d1, Δ = ∂f ∂S =-e-q^T-t N-d1+ Se-q^T-t N′-d1-Xe-r^T-t N′-d2 σ-S⁢T-t , Γ = ∂2f ∂S2 = Xe-r^T-t N′-d2+Se-q^T-t N′-d1 σ-S2T-t + Xe-r^T-t N′′-d2-Se-q^T-t N′′-d1 σ-2S2T-t , Θ = ∂f ∂t =rf+q-rSΔ- σ2S22Γ, Λ = ∂f ∂σ = Xd1 e-r^T-t N′-d2-S d2 e-q^T-t N′-d1 σ-2 σ^, ρ = ∂f ∂r =-XT-t e-r^T-t N-d2+ Se-q^T-t N′-d1-Xe-r^T-t N′-d2 T-tσ^.$
The analytic solution for an American call option with $q=0$ is identical to that for a European call, since early exercise is never optimal in this case. For all other cases no analytic solution is known.

## 9  Example

This example solves the Black–Scholes equation for valuation of a $5$-month American call option on a non-dividend-paying stock with an exercise price of \$50. The risk-free interest rate is 10% per annum, and the stock volatility is 40% per annum.
The option is valued at a range of times and stock prices.

### 9.1  Program Text

Program Text (d03ndce.c)

### 9.2  Program Data

Program Data (d03ndce.d)

### 9.3  Program Results

Program Results (d03ndce.r)

nag_pde_bs_1d_analytic (d03ndc) (PDF version)
d03 Chapter Contents
d03 Chapter Introduction
NAG C Library Manual