D03NDF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

D03NDF

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.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

SUBROUTINE D03NDF ( KOPT, X, S, T, TMAT, TDPAR, R, Q, SIGMA, F, THETA, DELTA, GAMMA, LAMBDA, RHO, IFAIL)
INTEGER  KOPT, IFAIL
REAL (KIND=nag_wp)  X, S, T, TMAT, R(*), Q(*), SIGMA(*), F, THETA, DELTA, GAMMA, LAMBDA, RHO
LOGICAL  TDPAR(3)

3  Description

D03NDF 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 D03NDF. An auxiliary routine D03NEF 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 .
D03NDF also returns values of the Greeks
Θ= f t ,   Δ= f x ,   Γ= 2f x2 ,   Λ= f σ ,   ρ= f r .
S30ABF 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  Parameters

1:     KOPT – INTEGERInput
On entry: specifies the kind of option to be valued:
KOPT=1
A European call option.
KOPT=2
An American call option.
KOPT=3
A European put option.
Constraints:
  • KOPT=1, 2 or 3;
  • if q0, KOPT2.
2:     X – REAL (KIND=nag_wp)Input
On entry: the exercise price X.
Constraint: X0.0.
3:     S – REAL (KIND=nag_wp)Input
On entry: the stock price at which the option value and the Greeks should be evaluated.
Constraint: S0.0.
4:     T – REAL (KIND=nag_wp)Input
On entry: the time at which the option value and the Greeks should be evaluated.
Constraint: T0.0.
5:     TMAT – REAL (KIND=nag_wp)Input
On entry: the maturity time of the option.
Constraint: TMATT.
6:     TDPAR(3) – LOGICAL arrayInput
On entry: specifies whether or not various parameters are time-dependent. More precisely, r is time-dependent if TDPAR1=.TRUE. and constant otherwise. Similarly, TDPAR2 specifies whether q is time-dependent and TDPAR3 specifies whether σ is time-dependent.
7:     R(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array R must be at least 3 if TDPAR1=.TRUE., and at least 1 otherwise.
On entry: if TDPAR1=.FALSE. then R1 must contain the constant value of r. The remaining elements need not be set.
If TDPAR1=.TRUE. then R1 must contain the value of r at time T and R2 must contain its average instantaneous value over the remaining life of the option:
r^=TTMATrζdζ.
The auxiliary routine D03NEF may be used to construct R from a set of values of r at discrete times.
8:     Q(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array Q must be at least 3 if TDPAR2=.TRUE., and at least 1 otherwise.
On entry: if TDPAR2=.FALSE. then Q1 must contain the constant value of q. The remaining elements need not be set.
If TDPAR2=.TRUE. then Q1 must contain the constant value of q and Q2 must contain its average instantaneous value over the remaining life of the option:
q^=TTMATqζdζ.
The auxiliary routine D03NEF may be used to construct Q from a set of values of q at discrete times.
9:     SIGMA(*) – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array SIGMA must be at least 3 if TDPAR3=.TRUE., and at least 1 otherwise.
On entry: if TDPAR3=.FALSE. then SIGMA1 must contain the constant value of σ. The remaining elements need not be set.
If TDPAR3=.TRUE. then SIGMA1 must contain the value of σ at time T, SIGMA2 the average instantaneous value σ^, and SIGMA3 the second-order average σ-, where:
σ^=TTMATσζdζ,
σ-= TTMAT σ2 ζ dζ 1/2 .
The auxiliary routine D03NEF may be used to compute SIGMA from a set of values at discrete times.
Constraints:
  • if TDPAR3=.FALSE., SIGMA1>0.0;
  • if TDPAR3=.TRUE., SIGMAi>0.0, for i=1,2,3.
10:   F – REAL (KIND=nag_wp)Output
On exit: the value f of the option at the stock price S and time T.
11:   THETA – REAL (KIND=nag_wp)Output
12:   DELTA – REAL (KIND=nag_wp)Output
13:   GAMMA – REAL (KIND=nag_wp)Output
14:   LAMBDA – REAL (KIND=nag_wp)Output
15:   RHO – REAL (KIND=nag_wp)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:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ 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​ 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 -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
IFAIL=1
On entry,KOPT<1,
orKOPT>3,
orKOPT=2 when q0,
orX<0.0,
orS<0.0,
orT<0.0,
orTMAT<T,
orSIGMA10.0, with TDPAR3=.FALSE.,
orSIGMAi0.0, with TDPAR3=.TRUE., for some i=1, 2 or 3.

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 D03NEF 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,
Nx is the cumulative Normal distribution function and Nx is its derivative
Nx = 12π -x e-ζ2/2dζ, Nx = 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 Nd1+ Se-q^T-t Nd1-Xe-r^T-t Nd2 σ-ST-t , Γ = 2 f S2 = Se-q^T-t Nd1+Xe-r^T-t Nd2 σ-S2T-t + Se-q^T-t Nd1-Xe-r^T-t Nd2 σ-2S2T-t , Θ = f t =rf+q-r SΔ- σ2 S22Γ, Λ = f σ = X d1 e-r^T-t Nd2-S d2 e-q^T-t Nd1 σ-2 σ^, ρ = f r =XT-t e-r^T-t Nd2+ Se-q^T-t Nd1-Xe-r^T-t Nd2 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 σ-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 (d03ndfe.f90)

9.2  Program Data

Program Data (d03ndfe.d)

9.3  Program Results

Program Results (d03ndfe.r)

Produced by GNUPLOT 4.4 patchlevel 0 -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 q d g l r
Produced by GNUPLOT 4.4 patchlevel 0 -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 q d g l r

D03NDF (PDF version)
D03 Chapter Contents
D03 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012