NAG Library Function Document
nag_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 <nag.h> |
#include <nagd03.h> |
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))
for the value
of a European put or call option, or an American call option with zero dividend
. In equation
(1) is time,
is the stock price,
is the exercise price,
is the risk free interest rate,
is the continuous dividend, and
is the stock volatility. The parameter
,
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 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. Equation
(1) is subject to different boundary conditions depending on the type of option. For a call option the boundary condition is
where
is the maturity time of the option. For a put option the equation
(1) is subject to
nag_pde_bs_1d_analytic (d03ndc) also returns values of the Greeks
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 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:
– Nag_OptionTypeInput
-
On entry: specifies the kind of option to be valued:
- A European call option.
- An American call option.
- A European put option.
Constraints:
- , or ;
- if , .
- 2:
– doubleInput
-
On entry: the exercise price .
Constraint:
.
- 3:
– doubleInput
-
On entry: the stock price at which the option value and the Greeks should be evaluated.
Constraint:
.
- 4:
– doubleInput
-
On entry: the time at which the option value and the Greeks should be evaluated.
Constraint:
.
- 5:
– doubleInput
-
On entry: the maturity time of the option.
Constraint:
.
- 6:
– const Nag_BooleanInput
-
On entry: specifies whether or not various arguments are time-dependent. More precisely, is time-dependent if and constant otherwise. Similarly, specifies whether is time-dependent and specifies whether is time-dependent.
- 7:
– const doubleInput
-
Note: the dimension,
dim, of the array
r
must be at least
- when ;
- otherwise.
On entry: if
then
must contain the constant value of
. The remaining elements need not be set.
If
then
must contain the value of
at time
t and
must contain its average instantaneous value over the remaining life of the option:
The auxiliary function
nag_pde_bs_1d_means (d03nec) may be used to construct
r from a set of values of
at discrete times.
- 8:
– const doubleInput
-
Note: the dimension,
dim, of the array
q
must be at least
- when ;
- otherwise.
On entry: if
then
must contain the constant value of
. The remaining elements need not be set.
If
then
must contain the constant value of
and
must contain its average instantaneous value over the remaining life of the option:
The auxiliary function
nag_pde_bs_1d_means (d03nec) may be used to construct
q from a set of values of
at discrete times.
- 9:
– const doubleInput
-
Note: the dimension,
dim, of the array
sigma
must be at least
- when ;
- otherwise.
On entry: if
then
must contain the constant value of
. The remaining elements need not be set.
If
then
must contain the value of
at time
t,
the average instantaneous value
, and
the second-order average
, where:
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 , ;
- if , , for .
- 10:
– double *Output
-
On exit: the value
of the option at the stock price
s and time
t.
- 11:
– double *Output
- 12:
– double *Output
- 13:
– double *Output
- 14:
– double *Output
- 15:
– double *Output
-
On exit: the values of various Greeks at the stock price
s and time
t, as follows:
- 16:
– NagError *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.
See
Section 3.2.1.2 in the Essential Introduction for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_INCOMPAT_PARAM
-
On entry, is not equal to with American call option.
.
On entry, and .
Constraint: .
- 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.
An unexpected error has been triggered by this function. Please contact
NAG.
See
Section 3.6.6 in the Essential Introduction for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 3.6.5 in the Essential Introduction for further information.
- NE_REAL
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_REAL_2
-
On entry, and .
Constraint: .
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
.
8 Parallelism and Performance
Not applicable.
9.1 Algorithmic Details
The Black–Scholes analytic formulae are used to compute the solution. For a European call option these are as follows:
where
is the cumulative Normal distribution function and
is its derivative
The functions
,
,
and
are average values of
,
and
over the time to maturity:
The Greeks are then calculated as follows:
Note: that is obtained from substitution of other Greeks in the Black–Scholes partial differential equation, rather than differentiation of . The values of , 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 with respect to , not .
For a European put option the equivalent equations are:
The analytic solution for an American call option with 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 -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)