Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_pde_1d_blackscholes_closed (d03nd)

## Purpose

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

## Syntax

[f, theta, delta, gamma, lambda, rho, ifail] = d03nd(kopt, x, s, t, tmat, tdpar, r, q, sigma)
[f, theta, delta, gamma, lambda, rho, ifail] = nag_pde_1d_blackscholes_closed(kopt, x, s, t, tmat, tdpar, r, q, sigma)

## Description

nag_pde_1d_blackscholes_closed (d03nd) 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 $∂f ∂t + (r-q) S ∂f ∂S + σ2 S2 2 ∂2f ∂S2 =rf$ (1)
 Smin < S < Smax,   tmin < t < tmax, $Smin< S (2)
for the value f$f$ of a European put or call option, or an American call option with zero dividend q$q$. In equation (1) t$t$ is time, S$S$ is the stock price, X$X$ is the exercise price, r$r$ is the risk free interest rate, q$q$ is the continuous dividend, and σ$\sigma$ is the stock volatility. The parameter r$r$, q$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_1d_blackscholes_closed (d03nd). An auxiliary function nag_pde_1d_blackscholes_means (d03ne) is available to compute such averages from values at a set of discrete times. Equation (1) is subject to different boundary conditions depending on the type of option. For a call option the boundary condition is
 f (S, t = tmat ) = max (0,S − X) $f (S, t = tmat ) = max (0,S-X)$
where tmat${t}_{\mathrm{mat}}$ is the maturity time of the option. For a put option the equation (1) is subject to
 f (S, t = tmat ) = max (0,X − S) . $f (S, t = tmat ) = max (0,X-S) .$
nag_pde_1d_blackscholes_closed (d03nd) also returns values of the Greeks
 Θ = ( ∂ f)/( ∂ t),   Δ = ( ∂ f)/( ∂ x),   Γ = (∂2f)/( ∂ x2),   Λ = ( ∂ f)/( ∂ σ),   ρ = ( ∂ f)/( ∂ r). $Θ= ∂f ∂t , Δ= ∂f ∂x , Γ= ∂2f ∂x2 , Λ= ∂f ∂σ , ρ= ∂f ∂r .$
nag_specfun_opt_bsm_greeks (s30ab) 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 [Algorithmic Details].

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

## Parameters

### Compulsory Input Parameters

1:     kopt – int64int32nag_int scalar
Specifies the kind of option to be valued:
kopt = 1${\mathbf{kopt}}=1$
A European call option.
kopt = 2${\mathbf{kopt}}=2$
An American call option.
kopt = 3${\mathbf{kopt}}=3$
A European put option.
Constraints:
• kopt = 1${\mathbf{kopt}}=1$, 2$2$ or 3$3$;
• if q0$q\ne 0$, kopt2${\mathbf{kopt}}\ne 2$.
2:     x – double scalar
The exercise price X$X$.
Constraint: x0.0${\mathbf{x}}\ge 0.0$.
3:     s – double scalar
The stock price at which the option value and the Greeks should be evaluated.
Constraint: s0.0${\mathbf{s}}\ge 0.0$.
4:     t – double scalar
The time at which the option value and the Greeks should be evaluated.
Constraint: t0.0${\mathbf{t}}\ge 0.0$.
5:     tmat – double scalar
The maturity time of the option.
Constraint: ${\mathbf{tmat}}\ge {\mathbf{t}}$.
6:     tdpar(3$3$) – logical array
Specifies whether or not various parameters are time-dependent. More precisely, r$r$ is time-dependent if tdpar(1) = true${\mathbf{tdpar}}\left(1\right)=\mathbf{true}$ and constant otherwise. Similarly, tdpar(2)${\mathbf{tdpar}}\left(2\right)$ specifies whether q$q$ is time-dependent and tdpar(3)${\mathbf{tdpar}}\left(3\right)$ specifies whether σ$\sigma$ is time-dependent.
7:     r( : $:$) – double array
Note: the dimension of the array r must be at least 3$3$ if tdpar(1) = true${\mathbf{tdpar}}\left(1\right)=\mathbf{true}$, and at least 1$1$ otherwise.
If tdpar(1) = false${\mathbf{tdpar}}\left(1\right)=\mathbf{false}$ then r(1)${\mathbf{r}}\left(1\right)$ must contain the constant value of r$r$. The remaining elements need not be set.
If tdpar(1) = true${\mathbf{tdpar}}\left(1\right)=\mathbf{true}$ then r(1)${\mathbf{r}}\left(1\right)$ must contain the value of r$r$ at time t and r(2)${\mathbf{r}}\left(2\right)$ must contain its average instantaneous value over the remaining life of the option:
 tmat r̂ = ∫ r(ζ)dζ. t
$r^=∫ttmatr(ζ)dζ.$
The auxiliary function nag_pde_1d_blackscholes_means (d03ne) may be used to construct r from a set of values of r$r$ at discrete times.
8:     q( : $:$) – double array
Note: the dimension of the array q must be at least 3$3$ if tdpar(2) = true${\mathbf{tdpar}}\left(2\right)=\mathbf{true}$, and at least 1$1$ otherwise.
If tdpar(2) = false${\mathbf{tdpar}}\left(2\right)=\mathbf{false}$ then q(1)${\mathbf{q}}\left(1\right)$ must contain the constant value of q$q$. The remaining elements need not be set.
If tdpar(2) = true${\mathbf{tdpar}}\left(2\right)=\mathbf{true}$ then q(1)${\mathbf{q}}\left(1\right)$ must contain the constant value of q$q$ and q(2)${\mathbf{q}}\left(2\right)$ must contain its average instantaneous value over the remaining life of the option:
 tmat q̂ = ∫ q(ζ)dζ. t
$q^=∫ttmatq(ζ)dζ.$
The auxiliary function nag_pde_1d_blackscholes_means (d03ne) may be used to construct q from a set of values of q$q$ at discrete times.
9:     sigma( : $:$) – double array
Note: the dimension of the array sigma must be at least 3$3$ if tdpar(3) = true${\mathbf{tdpar}}\left(3\right)=\mathbf{true}$, and at least 1$1$ otherwise.
If tdpar(3) = false${\mathbf{tdpar}}\left(3\right)=\mathbf{false}$ then sigma(1)${\mathbf{sigma}}\left(1\right)$ must contain the constant value of σ$\sigma$. The remaining elements need not be set.
If tdpar(3) = true${\mathbf{tdpar}}\left(3\right)=\mathbf{true}$ then sigma(1)${\mathbf{sigma}}\left(1\right)$ must contain the value of σ$\sigma$ at time t, sigma(2)${\mathbf{sigma}}\left(2\right)$ the average instantaneous value σ̂$\stackrel{^}{\sigma }$, and sigma(3)${\mathbf{sigma}}\left(3\right)$ the second-order average σ$\stackrel{-}{\sigma }$, where:
 tmat σ̂ = ∫ σ(ζ)dζ, t
$σ^=∫ttmatσ(ζ)dζ,$
σ =
 (tmat ) ∫ σ2(ζ)dζt 1 / 2
.
$σ-= ( ∫ttmat σ2 (ζ) dζ ) 1/2 .$
The auxiliary function nag_pde_1d_blackscholes_means (d03ne) may be used to compute sigma from a set of values at discrete times.
Constraints:
• if tdpar(3) = false${\mathbf{tdpar}}\left(3\right)=\mathbf{false}$, sigma(1) > 0.0${\mathbf{sigma}}\left(1\right)>0.0$;
• if tdpar(3) = true${\mathbf{tdpar}}\left(3\right)=\mathbf{true}$, sigma(i) > 0.0${\mathbf{sigma}}\left(\mathit{i}\right)>0.0$, for i = 1,2,3$\mathit{i}=1,2,3$.

None.

None.

### Output Parameters

1:     f – double scalar
The value f$f$ of the option at the stock price s and time t.
2:     theta – double scalar
3:     delta – double scalar
4:     gamma – double scalar
5:     lambda – double scalar
6:     rho – double scalar
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).
$theta=Θ= ∂f ∂t , delta=Δ= ∂f ∂s , gamma=Γ= ∂2f ∂s2 , lambda=Λ= ∂f ∂σ , rho=ρ= ∂f ∂r .$
7:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, kopt < 1${\mathbf{kopt}}<1$, or kopt > 3${\mathbf{kopt}}>3$, or kopt = 2${\mathbf{kopt}}=2$ when q ≠ 0$q\ne 0$, or x < 0.0${\mathbf{x}}<0.0$, or s < 0.0${\mathbf{s}}<0.0$, or t < 0.0${\mathbf{t}}<0.0$, or ${\mathbf{tmat}}<{\mathbf{t}}$, or sigma(1) ≤ 0.0${\mathbf{sigma}}\left(1\right)\le 0.0$, with tdpar(3) = false${\mathbf{tdpar}}\left(3\right)=\mathbf{false}$, or sigma(i) ≤ 0.0${\mathbf{sigma}}\left(i\right)\le 0.0$, with tdpar(3) = true${\mathbf{tdpar}}\left(3\right)=\mathbf{true}$, for some i = 1$i=1$, 2$2$ or 3$3$.

## 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_1d_blackscholes_means (d03ne) are exact for polynomials of degree up to 3$3$.

## Further Comments

### 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) N(d2) $f= S e -q^ (T-t) N (d1)- X e -r^ (T-t) N(d2)$
where
 d1 = (log(S / X) + (r̂ − q̂ + σ2 / 2)(T − t))/(σsqrt(T − t)), d2 = (log(S / X) + (r̂ − q̂ − σ2 / 2)(T − t))/(σsqrt(T − t)) = d1 − σsqrt(T − t),
$d1 = log(S/X)+(r^-q^+σ-2/2)(T-t) σ-T-t , d2 = log(S/X)+(r^-q^-σ-2/2)(T-t) σ-T-t =d1-σ-T-t,$
N(x)$N\left(x\right)$ is the cumulative Normal distribution function and N(x)${N}^{\prime }\left(x\right)$ is its derivative
N(x) =
 x 1/(sqrt(2π)) ∫ e − ζ2 / 2dζ, − ∞
N(x) = 1/(sqrt(2π)) ex2 / 2.
$N(x) = 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$q$, r$r$ and σ$\sigma$ over the time to maturity:
q̂ = T 1/(T − t) ∫ q(ζ)dζ, t r̂ = T 1/(T − t) ∫ r(ζ)dζ, t σ̂ = T 1/(T − t) ∫ σ(ζ)dζ, t σ =
 ( T )1/(T − t) ∫ σ2(ζ)dζ t 1 / 2
.
$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) N(d1) + (Se − q̂(T − t) N′(d1) − Xe − r̂(T − t) N′(d2))/(σS×sqrt(T − t)), Γ = (∂2 f)/( ∂ S2) = (Se − q̂(T − t) N′(d1) + Xe − r̂(T − t) N′(d2))/(σS2sqrt(T − t)) + (Se − q̂(T − t) N′(d1) − Xe − r̂(T − t) N′(d2))/(σ2S2(T − t)), Θ = ( ∂ f)/( ∂ t) = rf + (q − r) SΔ − (σ2 S2)/2Γ, Λ = ( ∂ f)/( ∂ σ) = ((X d1 e − r̂(T − t) N′(d2) − S d2 e − q̂(T − t) N′(d1))/(σ2)) σ̂, ρ = ( ∂ f)/( ∂ r) = X(T − t) e − r̂(T − t) N(d2) + ((Se − q̂(T − t)N′(d1) − Xe − r̂(T − t)N′(d2)) sqrt(T − t))/(σ).
$Δ = ∂f ∂S =e-q^(T-t) N(d1)+ 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) σ-2S2(T-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 =X(T-t) e-r^(T-t) N(d2)+ (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$f$. The values of q$q$, r$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$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×sqrt(T − t)), Γ = (∂2f)/( ∂ S2) = (Xe − r̂(T − t) N′( − d2) + Se − q̂(T − t) N′( − d1))/(σS2sqrt(T − t)) + (Xe − r̂(T − t) N ′ ′ ( − d2) − Se − q̂(T − t) N ′ ′ ( − d1))/(σ2S2(T − t)), Θ = ( ∂ f)/( ∂ t) = rf + (q − r)SΔ − (σ2S2)/2Γ, Λ = ( ∂ f)/( ∂ σ) = ((Xd1 e − r̂(T − t) N′( − d2) − S d2 e − q̂(T − t) N′( − d1))/(σ2)) σ̂, ρ = ( ∂ f)/( ∂ r) = − X(T − t) e − r̂(T − t) N( − d2) + ((Se − q̂(T − t)N′( − d1) − Xe − r̂(T − t)N′( − d2)) sqrt(T − t))/(σ̂).
$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) σ-2S2(T-t) , Θ = ∂f ∂t =rf+(q-r)SΔ- σ2S22Γ, Λ = ∂f ∂σ =( Xd1 e-r^(T-t) N′(-d2)-S d2 e-q^(T-t) N′(-d1) σ-2 ) σ^, ρ = ∂f ∂r =-X(T-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$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.

## Example

```function nag_pde_1d_blackscholes_closed_example
kopt = int64(2);
x = 50;
s = 0;
t = 0;
tmat = 0.4166667;
tdpar = [false; false; false];
r = [0.1];
q = [0];
sigma = [0.4];
[f, theta, delta, gamma, lambda, rho, ifail] = ...
nag_pde_1d_blackscholes_closed(kopt, x, s, t, tmat, tdpar, r, q, sigma)
```
```

f =

0

theta =

0

delta =

0

gamma =

0

lambda =

0

rho =

0

ifail =

0

```
```function d03nd_example
kopt = int64(2);
x = 50;
s = 0;
t = 0;
tmat = 0.4166667;
tdpar = [false; false; false];
r = [0.1];
q = [0];
sigma = [0.4];
[f, theta, delta, gamma, lambda, rho, ifail] = ...
d03nd(kopt, x, s, t, tmat, tdpar, r, q, sigma)
```
```

f =

0

theta =

0

delta =

0

gamma =

0

lambda =

0

rho =

0

ifail =

0

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013