Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_pde_1d_blackscholes_means (d03ne)

## Purpose

nag_pde_1d_blackscholes_means (d03ne) computes average values of a continuous function of time over the remaining life of an option. It is used together with nag_pde_1d_blackscholes_closed (d03nd) to value options with time-dependent parameters.

## Syntax

[phiav, ifail] = d03ne(t0, tmat, td, phid, 'ntd', ntd)
[phiav, ifail] = nag_pde_1d_blackscholes_means(t0, tmat, td, phid, 'ntd', ntd)

## Description

nag_pde_1d_blackscholes_means (d03ne) computes the quantities
φ(t0),   T ϕ̂ = 1/(T − t0) ∫ φ(ζ)dζ,   t0 φ =
 ( T )1/(T − t0) ∫ φ2(ζ)dζ t0 1 / 2
$ϕ(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)$\varphi \left(t\right)$ at a set of discrete points td, where t0${t}_{0}$ is the current time and T$T$ is the maturity time. Thus ϕ̂$\stackrel{^}{\varphi }$ and φ$\stackrel{-}{\varphi }$ are first and second order averages of φ$\varphi$ over the remaining life of an option.
The function may be used in conjunction with nag_pde_1d_blackscholes_closed (d03nd) in order to value an option in the case where the risk-free interest rate r$r$, the continuous dividend q$q$, or the stock volatility σ$\sigma$ is time-dependent and is described by values at a set of discrete times (see Section [Use with ]). This is illustrated in Section [Example].

None.

## Parameters

### Compulsory Input Parameters

1:     t0 – double scalar
The current time t0${t}_{0}$.
Constraint: td(1)t0td(ntd)${\mathbf{td}}\left(1\right)\le {\mathbf{t0}}\le {\mathbf{td}}\left({\mathbf{ntd}}\right)$.
2:     tmat – double scalar
The maturity time T$T$.
Constraint: td(1)tmattd(ntd)${\mathbf{td}}\left(1\right)\le {\mathbf{tmat}}\le {\mathbf{td}}\left({\mathbf{ntd}}\right)$.
3:     td(ntd) – double array
ntd, the dimension of the array, must satisfy the constraint ntd2${\mathbf{ntd}}\ge 2$.
The discrete times at which φ$\varphi$ is specified.
Constraint: td(1) < td(2) < < td(ntd)${\mathbf{td}}\left(1\right)<{\mathbf{td}}\left(2\right)<\cdots <{\mathbf{td}}\left({\mathbf{ntd}}\right)$.
4:     phid(ntd) – double array
ntd, the dimension of the array, must satisfy the constraint ntd2${\mathbf{ntd}}\ge 2$.
phid(i)${\mathbf{phid}}\left(\mathit{i}\right)$ must contain the value of φ$\varphi$ at time td(i)${\mathbf{td}}\left(\mathit{i}\right)$, for i = 1,2,,ntd$\mathit{i}=1,2,\dots ,{\mathbf{ntd}}$.

### Optional Input Parameters

1:     ntd – int64int32nag_int scalar
Default: The dimension of the arrays td, phid. (An error is raised if these dimensions are not equal.)
The number of discrete times at which φ$\varphi$ is given.
Constraint: ntd2${\mathbf{ntd}}\ge 2$.

work lwork

### Output Parameters

1:     phiav(3$3$) – double array
phiav(1)${\mathbf{phiav}}\left(1\right)$ contains the value of φ$\varphi$ interpolated to t0${t}_{0}$, phiav(2)${\mathbf{phiav}}\left(2\right)$ contains the first-order average ϕ̂$\stackrel{^}{\varphi }$ and phiav(3)${\mathbf{phiav}}\left(3\right)$ contains the second-order average φ$\stackrel{-}{\varphi }$, where:
T ϕ̂ = 1/(T − t0) ∫ φ(ζ)dζ,   t0 φ =
 ( T )1/(T − t0) ∫ φ2(ζ)dζ t0 1 / 2
.
$ϕ^=1T-t0 ∫t0Tϕ(ζ)dζ , ϕ-= (1T-t0 ∫t0Tϕ2(ζ)dζ) 1/2 .$
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, t0 lies outside the range [td(1),td(ntd)${\mathbf{td}}\left(1\right),{\mathbf{td}}\left({\mathbf{ntd}}\right)$], or tmat lies outside the range [td(1),td(ntd)${\mathbf{td}}\left(1\right),{\mathbf{td}}\left({\mathbf{ntd}}\right)$], or ntd < 2${\mathbf{ntd}}<2$, or td badly ordered, or lwork < 9 × ntd + 24$\mathit{lwork}<9×{\mathbf{ntd}}+24$.
ifail = 2${\mathbf{ifail}}=2$
Unexpected failure in internal call to nag_interp_1d_spline (e01ba) or nag_fit_1dspline_eval (e02bb).

## Accuracy

If φC4[t0,T]$\varphi \in {C}^{4}\left[{t}_{0},T\right]$ then the error in the approximation of φ(t0)$\varphi \left({t}_{0}\right)$ and ϕ̂$\stackrel{^}{\varphi }$ is O(H4)$\mathit{O}\left({H}^{4}\right)$, where H = maxi (T(i + 1)T(i))$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,,ntd1$i=1,2,\dots ,{\mathbf{ntd}}-1$. The approximation is exact for polynomials of degree up to 3$3$.
The third quantity φ$\stackrel{-}{\varphi }$ is O(H2)$\mathit{O}\left({H}^{2}\right)$, and exact for linear functions.

### Timing

The time taken is proportional to ntd.

### Use with nag_pde_1d_blackscholes_closed (d03nd)

Suppose you wish to evaluate the analytic solution of the Black–Scholes equation in the case when the risk-free interest rate r$r$ is a known function of time, and is represented as a set of values at discrete times. A call to nag_pde_1d_blackscholes_means (d03ne) providing these values in phid produces an output array phiav suitable for use as the argument r in a subsequent call to nag_pde_1d_blackscholes_closed (d03nd).
Time-dependent values of the continuous dividend Q$Q$ and the volatility σ$\sigma$ may be handled in the same way.

### Algorithmic Details

The ntd data points are fitted with a cubic B-spline using the function nag_interp_1d_spline (e01ba). Evaluation is then performed using nag_fit_1dspline_eval (e02bb), and the definite integrals are computed using direct integration of the cubic splines in each interval. The special case of T = to$T={t}_{o}$ is handled by interpolating φ$\varphi$ at that point.

## Example

```function nag_pde_1d_blackscholes_means_example
t0 = 0;
tmat = 0.4166667;
td = [0;
0.1;
0.2;
0.3;
0.4;
0.5];
phid = [0.1;
0.11;
0.12;
0.13;
0.14;
0.15];
[phiav, ifail] = nag_pde_1d_blackscholes_means(t0, tmat, td, phid)
```
```

phiav =

0.1000
0.1208
0.1214

ifail =

0

```
```function d03ne_example
t0 = 0;
tmat = 0.4166667;
td = [0;
0.1;
0.2;
0.3;
0.4;
0.5];
phid = [0.1;
0.11;
0.12;
0.13;
0.14;
0.15];
[phiav, ifail] = d03ne(t0, tmat, td, phid)
```
```

phiav =

0.1000
0.1208
0.1214

ifail =

0

```