# NAG FL Interfaced03nef (dim1_​blackscholes_​means)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine d03nef ( t0, tmat, ntd, td, phid, work,
 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)
#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.

## 3Description

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 $\varphi \left(t\right)$ at a set of discrete points td, where ${t}_{0}$ is the current time and $T$ is the maturity time. Thus $\stackrel{^}{\varphi }$ and $\overline{\varphi }$ are first and second order averages of $\varphi$ 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 $\sigma$ is time-dependent and is described by values at a set of discrete times (see Section 9.2).

None.

## 5Arguments

1: $\mathbf{t0}$Real (Kind=nag_wp) Input
On entry: the current time ${t}_{0}$.
Constraint: ${\mathbf{td}}\left(1\right)\le {\mathbf{t0}}\le {\mathbf{td}}\left({\mathbf{ntd}}\right)$.
2: $\mathbf{tmat}$Real (Kind=nag_wp) Input
On entry: the maturity time $T$.
Constraint: ${\mathbf{td}}\left(1\right)\le {\mathbf{tmat}}\le {\mathbf{td}}\left({\mathbf{ntd}}\right)$.
3: $\mathbf{ntd}$Integer Input
On entry: the number of discrete times at which $\varphi$ is given.
Constraint: ${\mathbf{ntd}}\ge 2$.
4: $\mathbf{td}\left({\mathbf{ntd}}\right)$Real (Kind=nag_wp) array Input
On entry: the discrete times at which $\varphi$ is specified.
Constraint: ${\mathbf{td}}\left(1\right)<{\mathbf{td}}\left(2\right)<\cdots <{\mathbf{td}}\left({\mathbf{ntd}}\right)$.
5: $\mathbf{phid}\left({\mathbf{ntd}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\mathbf{phid}}\left(\mathit{i}\right)$ must contain the value of $\varphi$ at time ${\mathbf{td}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{ntd}}$.
6: $\mathbf{phiav}\left(3\right)$Real (Kind=nag_wp) array Output
On exit: ${\mathbf{phiav}}\left(1\right)$ contains the value of $\varphi$ interpolated to ${t}_{0}$, ${\mathbf{phiav}}\left(2\right)$ contains the first-order average $\stackrel{^}{\varphi }$ and ${\mathbf{phiav}}\left(3\right)$ contains the second-order average $\overline{\varphi }$, where:
 $ϕ^=1T-t0 ∫t0Tϕ(ζ)dζ , ϕ¯= (1T-t0 ∫t0Tϕ2(ζ)dζ) 1/2 .$
7: $\mathbf{work}\left({\mathbf{lwork}}\right)$Real (Kind=nag_wp) array Workspace
8: $\mathbf{lwork}$Integer Input
On entry: the dimension of the array work as declared in the (sub)program from which d03nef is called.
Constraint: ${\mathbf{lwork}}\ge 9×{\mathbf{ntd}}+24$.
9: $\mathbf{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 $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{lwork}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lwork}}\ge ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{ntd}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ntd}}\ge 2$.
On entry, ${\mathbf{t0}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{td}}\left(1\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{td}}\left({\mathbf{ntd}}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{td}}\left(1\right)\le {\mathbf{t0}}\le {\mathbf{td}}\left({\mathbf{ntd}}\right)$.
On entry, ${\mathbf{td}}\left(⟨\mathit{\text{value}}⟩+1\right)\le {\mathbf{td}}\left(⟨\mathit{\text{value}}⟩\right)$.
Constraint: ${\mathbf{td}}\left(1\right)<{\mathbf{td}}\left(2\right)<\cdots <{\mathbf{td}}\left({\mathbf{ntd}}\right)$.
On entry, ${\mathbf{tmat}}=⟨\mathit{\text{value}}⟩$, ${\mathbf{td}}\left(1\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{td}}\left({\mathbf{ntd}}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{td}}\left(1\right)\le {\mathbf{tmat}}\le {\mathbf{td}}\left({\mathbf{ntd}}\right)$.
${\mathbf{ifail}}=2$
Unexpected failure in internal call to spline routine.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

If $\varphi \in {C}^{4}\left[{t}_{0},T\right]$ then the error in the approximation of $\varphi \left({t}_{0}\right)$ and $\stackrel{^}{\varphi }$ is $\mathit{O}\left({H}^{4}\right)$, where $H=\underset{i}{\mathrm{max}}\phantom{\rule{0.25em}{0ex}}\left(T\left(i+1\right)-T\left(i\right)\right)$, for $i=1,2,\dots ,{\mathbf{ntd}}-1$. The approximation is exact for polynomials of degree up to $3$.
The third quantity $\overline{\varphi }$ is $\mathit{O}\left({H}^{2}\right)$, and exact for linear functions.

## 8Parallelism and Performance

d03nef is not threaded in any implementation.

### 9.1Timing

The time taken is proportional to ntd.

### 9.2Use 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 $\sigma$ may be handled in the same way.

### 9.3Algorithmic 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={t}_{o}$ is handled by interpolating $\varphi$ at that point.

## 10Example

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.1Program Text

Program Text (d03nefe.f90)

### 10.2Program Data

Program Data (d03nefe.d)

### 10.3Program Results

Program Results (d03nefe.r)