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
Subroutine d03nef ( t0, tmat, ntd, td, phid, phiav, work, lwork, ifail)
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)
The routine may be called by the names d03nef or nagf_pde_dim1_blackscholes_means.

3 Description

d03nef computes the quantities
ϕt0,   ϕ^=1T-t0 t0Tϕζdζ,   ϕ¯= 1T-t0 t0Tϕ2ζdζ 1/2  
from a given set of values phid of a continuous time-dependent function ϕt at a set of discrete points td, where t0 is the current time and T 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 r, the continuous dividend q, 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: t0 Real (Kind=nag_wp) Input
On entry: the current time t0.
Constraint: td1t0tdntd.
2: tmat Real (Kind=nag_wp) Input
On entry: the maturity time T.
Constraint: td1tmattdntd.
3: ntd Integer Input
On entry: the number of discrete times at which ϕ is given.
Constraint: ntd2.
4: tdntd Real (Kind=nag_wp) array Input
On entry: the discrete times at which ϕ is specified.
Constraint: td1<td2<<tdntd.
5: phidntd Real (Kind=nag_wp) array Input
On entry: phidi must contain the value of ϕ at time tdi, for i=1,2,,ntd.
6: phiav3 Real (Kind=nag_wp) array Output
On exit: phiav1 contains the value of ϕ interpolated to t0, phiav2 contains the first-order average ϕ^ and phiav3 contains the second-order average ϕ¯, where:
ϕ^=1T-t0 t0Tϕζdζ ,   ϕ¯= 1T-t0 t0Tϕ2ζdζ 1/2 .  
7: worklwork Real (Kind=nag_wp) array Workspace
8: lwork Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which d03nef is called.
Constraint: lwork9×ntd+24.
9: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of -1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value -1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. 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, lwork=value.
Constraint: lworkvalue.
On entry, ntd=value.
Constraint: ntd2.
On entry, t0=value, td1=value and tdntd=value.
Constraint: td1t0tdntd.
On entry, tdvalue+1tdvalue.
Constraint: td1<td2<<tdntd.
On entry, tmat=value, td1=value and tdntd=value.
Constraint: td1tmattdntd.
ifail=2
Unexpected failure in internal call to spline routine.
ifail=-99
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.
ifail=-399
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.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

If ϕC4t0,T then the error in the approximation of ϕt0 and ϕ^ is OH4, where H=maxiTi+1-Ti, for i=1,2,,ntd-1. The approximation is exact for polynomials of degree up to 3.
The third quantity ϕ¯ is OH2, and exact for linear functions.

8 Parallelism and Performance

d03nef is not threaded in any implementation.

9 Further Comments

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 r 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 Q 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 T=to 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 5-month American call option on a non-dividend-paying stock with an exercise price of $50. 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

Program Text (d03nefe.f90)

10.2 Program Data

Program Data (d03nefe.d)

10.3 Program Results

Program Results (d03nefe.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