NAG FL Interface
d03nef (dim1_blackscholes_means)
1
Purpose
d03nef computes average values of a continuous function of time over the remaining life of an option. It is used together with
d03ndf to value options with time-dependent arguments.
2
Specification
Fortran Interface
Integer, Intent (In) |
:: |
ntd, lwork |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
t0, tmat, td(ntd), phid(ntd) |
Real (Kind=nag_wp), Intent (Out) |
:: |
phiav(3), work(lwork) |
|
C Header Interface
#include <nag.h>
void |
d03nef_ (const double *t0, const double *tmat, const Integer *ntd, const double td[], const double phid[], double phiav[], double work[], const Integer *lwork, Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
d03nef_ (const double &t0, const double &tmat, const Integer &ntd, const double td[], const double phid[], double phiav[], double work[], const Integer &lwork, Integer &ifail) |
}
|
The routine may be called by the names d03nef or nagf_pde_dim1_blackscholes_means.
3
Description
d03nef computes the quantities
from a given set of values
phid of a continuous time-dependent function
at a set of discrete points
td, where
is the current time and
is the maturity time. Thus
and
are first and second order averages of
over the remaining life of an option.
The routine may be used in conjunction with
d03ndf in order to value an option in the case where the risk-free interest rate
, the continuous dividend
, or the stock volatility
is time-dependent and is described by values at a set of discrete times (see
Section 9.2). This is illustrated in
Section 10.
4
References
None.
5
Arguments
-
1:
– Real (Kind=nag_wp)
Input
-
On entry: the current time .
Constraint:
.
-
2:
– Real (Kind=nag_wp)
Input
-
On entry: the maturity time .
Constraint:
.
-
3:
– Integer
Input
-
On entry: the number of discrete times at which is given.
Constraint:
.
-
4:
– Real (Kind=nag_wp) array
Input
-
On entry: the discrete times at which is specified.
Constraint:
.
-
5:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain the value of at time , for .
-
6:
– Real (Kind=nag_wp) array
Output
-
On exit:
contains the value of
interpolated to
,
contains the first-order average
and
contains the second-order average
, where:
-
7:
– Real (Kind=nag_wp) array
Workspace
-
8:
– Integer
Input
-
On entry: the dimension of the array
work as declared in the (sub)program from which
d03nef is called.
Constraint:
.
-
9:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, , and .
Constraint: .
On entry, .
Constraint: .
On entry, , and .
Constraint: .
-
Unexpected failure in internal call to spline routine.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
If then the error in the approximation of and is , where , for . The approximation is exact for polynomials of degree up to .
The third quantity is , and exact for linear functions.
8
Parallelism and Performance
d03nef is not threaded in any implementation.
9.1
Timing
The time taken is proportional to
ntd.
9.2
Use with d03ndf
Suppose you wish to evaluate the analytic solution of the Black–Scholes equation in the case when the risk-free interest rate
is a known function of time, and is represented as a set of values at discrete times. A call to
d03nef providing these values in
phid produces an output array
phiav suitable for use as the argument
r in a subsequent call to
d03ndf.
Time-dependent values of the continuous dividend and the volatility may be handled in the same way.
9.3
Algorithmic Details
The
ntd data points are fitted with a cubic B-spline using the routine
e01baf. Evaluation is then performed using
e02bbf, and the definite integrals are computed using direct integration of the cubic splines in each interval. The special case of
is handled by interpolating
at that point.
10
Example
This example demonstrates the use of the routine in conjunction with
d03ndf to solve the Black–Scholes equation for valuation of a
-month American call option on a non-dividend-paying stock with an exercise price of $
. The risk-free interest rate varies linearly with time and the stock volatility has a quadratic variation. Since these functions are integrated exactly by
d03nef the solution of the Black–Scholes equation by
d03ndf is also exact.
The option is valued at a range of times and stock prices.
10.1
Program Text
10.2
Program Data
10.3
Program Results