NAG CL Interface
d03ndc (dim1_​blackscholes_​closed)

Settings help

CL Name Style:


1 Purpose

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

2 Specification

#include <nag.h>
void  d03ndc (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)
The function may be called by the names: d03ndc, nag_pde_dim1_blackscholes_closed or nag_pde_bs_1d_analytic.

3 Description

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<Smax,   tmin<t< tmax, (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 σ is the stock volatility. The parameter r, q and σ 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 d03ndc. An auxiliary function d03nec 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)  
where tmat 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) .  
d03ndc also returns values of the Greeks
Θ= f t ,   Δ= f x ,   Γ= 2f x2 ,   Λ= f σ ,   ρ= f r .  
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 9.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: kopt Nag_OptionType Input
On entry: specifies the kind of option to be valued:
kopt=Nag_EuropeanCall
A European call option.
kopt=Nag_AmericanCall
An American call option.
kopt=Nag_EuropeanPut
A European put option.
Constraints:
  • kopt=Nag_EuropeanCall, Nag_AmericanCall or Nag_EuropeanPut;
  • if q0, koptNag_AmericanCall.
2: x double Input
On entry: the exercise price X.
Constraint: x0.0.
3: s double Input
On entry: the stock price at which the option value and the Greeks should be evaluated.
Constraint: s0.0.
4: t double Input
On entry: the time at which the option value and the Greeks should be evaluated.
Constraint: t0.0.
5: tmat double Input
On entry: the maturity time of the option.
Constraint: tmatt.
6: tdpar[3] const Nag_Boolean Input
On entry: specifies whether or not various arguments are time-dependent. More precisely, r is time-dependent if tdpar[0]=Nag_TRUE and constant otherwise. Similarly, tdpar[1] specifies whether q is time-dependent and tdpar[2] specifies whether σ is time-dependent.
7: r[dim] const double Input
Note: the dimension, dim, of the array r must be at least
  • 3 when tdpar[0]=Nag_TRUE;
  • 1 otherwise.
On entry: if tdpar[0]=Nag_FALSE then r[0] must contain the constant value of r. The remaining elements need not be set.
If tdpar[0]=Nag_TRUE then r[0] must contain the value of r at time t and r[1] must contain its average instantaneous value over the remaining life of the option:
r^=ttmatr(ζ)dζ.  
The auxiliary function d03nec may be used to construct r from a set of values of r at discrete times.
8: q[dim] const double Input
Note: the dimension, dim, of the array q must be at least
  • 3 when tdpar[1]=Nag_TRUE;
  • 1 otherwise.
On entry: if tdpar[1]=Nag_FALSE then q[0] must contain the constant value of q. The remaining elements need not be set.
If tdpar[1]=Nag_TRUE then q[0] must contain the constant value of q and q[1] must contain its average instantaneous value over the remaining life of the option:
q^=ttmatq(ζ)dζ.  
The auxiliary function d03nec may be used to construct q from a set of values of q at discrete times.
9: sigma[dim] const double Input
Note: the dimension, dim, of the array sigma must be at least
  • 3 when tdpar[2]=Nag_TRUE;
  • 1 otherwise.
On entry: if tdpar[2]=Nag_FALSE then sigma[0] must contain the constant value of σ. The remaining elements need not be set.
If tdpar[2]=Nag_TRUE then sigma[0] must contain the value of σ at time t, sigma[1] the average instantaneous value σ^, and sigma[2] the second-order average σ¯, where:
σ^=ttmatσ(ζ)dζ,  
σ¯= (ttmatσ2(ζ)dζ) 1/2 .  
The auxiliary function d03nec may be used to compute sigma from a set of values at discrete times.
Constraints:
  • if tdpar[2]=Nag_FALSE, sigma[0]>0.0;
  • if tdpar[2]=Nag_TRUE, sigma[i-1]>0.0, for i=1,2,3.
10: f double * Output
On exit: the value f of the option at the stock price s and time t.
11: theta double * Output
12: delta double * Output
13: gamma double * Output
14: lambda double * Output
15: rho double * 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: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INCOMPAT_PARAM
On entry, q[0] is not equal to 0.0 with American call option. q[0]=value.
On entry, sigma[value]=value.
Constraint: sigma[i-1]>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.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL
On entry, s=value.
Constraint: s0.0.
On entry, t=value.
Constraint: t0.0.
On entry, x=value.
Constraint: x0.0.
NE_REAL_2
On entry, tmat=value and t=value.
Constraint: tmatt.

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 d03nec are exact for polynomials of degree up to 3.

8 Parallelism and Performance

d03ndc is not threaded in any implementation.

9 Further Comments

9.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) N(d2)  
where
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) is the cumulative Normal distribution function and N(x) is its derivative
N(x) = 12π -x e-ζ2/2dζ, N(x) = 12π e-x2/2.  
The functions q^, r^, σ^ and σ¯ are average values of q, r and σ 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) N(d1)+ Se-q^(T-t) N(d1)-Xe-r^(T-t) N(d2) σ¯ST-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 Θ 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 σ appearing in its definition are the instantaneous values, not the averages. Note also that both the first-order average σ^ and the second-order average σ¯ appear in the expression for Λ. This results from the fact that Λ is the derivative of f with respect to σ, not σ^.
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) σ¯ST-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 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.

10 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.

10.1 Program Text

Program Text (d03ndce.c)

10.2 Program Data

Program Data (d03ndce.d)

10.3 Program Results

Program Results (d03ndce.r)
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −30 −20 −10 0 10 20 30 40 50 0 20 40 60 80 100 −10 −5 0 5 10 15 20 Option Values Derivatives Stock Price Example Program 1 Option Values and Derivatives at 5 Months to Maturity option values θ δ γ λ ρ gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3 gnuplot_plot_4 gnuplot_plot_5 gnuplot_plot_6
GnuplotProduced by GNUPLOT 4.6 patchlevel 3 −30 −20 −10 0 10 20 30 40 50 0 20 40 60 80 100 −10 −5 0 5 10 15 20 Option Values Derivatives Stock Price Example Program 2 Option Values and Derivatives at 3.5 Months to Maturity option values θ δ γ λ ρ gnuplot_plot_1 gnuplot_plot_2 gnuplot_plot_3 gnuplot_plot_4 gnuplot_plot_5 gnuplot_plot_6