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

NAG Library Routine Document

D03NEF

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

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

2  Specification

SUBROUTINE D03NEF ( T0, TMAT, NTD, TD, PHID, PHIAV, WORK, LWORK, IFAIL)
INTEGER  NTD, LWORK, IFAIL
REAL (KIND=nag_wp)  T0, TMAT, TD(NTD), PHID(NTD), PHIAV(3), WORK(LWORK)

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  Parameters

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 – INTEGERInput
On entry: the number of discrete times at which ϕ is given.
Constraint: NTD2.
4:     TDNTD – REAL (KIND=nag_wp) arrayInput
On entry: the discrete times at which ϕ is specified.
Constraint: TD1<TD2<<TDNTD.
5:     PHIDNTD – REAL (KIND=nag_wp) arrayInput
On entry: PHIDi must contain the value of ϕ at time TDi, for i=1,2,,NTD.
6:     PHIAV3 – REAL (KIND=nag_wp) arrayOutput
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) arrayWorkspace
8:     LWORK – INTEGERInput
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 – 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,T0 lies outside the range [TD1,TDNTD],
orTMAT lies outside the range [TD1,TDNTD],
orNTD<2,
orTD badly ordered,
orLWORK<9×NTD+24.
IFAIL=2
Unexpected failure in internal call to E01BAF or E02BBF.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction 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

Not applicable.

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

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

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