# NAG FL Interfacee01cef (dim1_​monconv_​disc)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

e01cef computes, for a given set of data points, the forward values and other values required for monotone convex interpolation as defined in Hagan and West (2008). This form of interpolation is particularly suited to the construction of yield curves in Financial Mathematics but can be applied to any data where it is desirable to preserve both monotonicity and convexity.

## 2Specification

Fortran Interface
 Subroutine e01cef ( n, lam, yfor, x, y, comm,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: lam, x(n), y(n) Real (Kind=nag_wp), Intent (Out) :: comm(4*n+10) Logical, Intent (In) :: negfor, yfor
#include <nag.h>
 void e01cef_ (const Integer *n, const double *lam, const logical *negfor, const logical *yfor, const double x[], const double y[], double comm[], Integer *ifail)
The routine may be called by the names e01cef or nagf_interp_dim1_monconv_disc.

## 3Description

e01cef computes, for a set of data points, $\left({x}_{i},{y}_{i}\right)$, for $\mathit{i}=1,2,\dots ,n$, the discrete forward rates, ${f}_{i}^{d}$, and the instantaneous forward rates, ${f}_{i}$, which are used in a monotone convex interpolation method that attempts to preserve both the monotonicity and the convexity of the original data. The monotone convex interpolation method is due to Hagan and West and is described in Hagan and West (2006), Hagan and West (2008) and West (2011).
The discrete forward rates are defined simply, for ordered data, by
 $f1d=y1; fid = xi yi - xi-1 yi-1 xi - xi-1 , for ​ i=2,3,…,n.$ (1)
The discrete forward rates, if pre-computed, may be supplied instead of $y$, in which case the original values $y$ are computed using the inverse of (1).
The data points ${x}_{i}$ need not be ordered on input (though ${y}_{i}$ must correspond to ${x}_{i}$); a set of ordered and scaled values ${\xi }_{i}$ are calculated from ${x}_{i}$ and stored.
In its simplest form, the instantaneous forward rates, ${f}_{i}$, at the data points are computed as linear interpolations of the ${f}_{i}^{d}$:
 $fi = xi - xi-1 xi+1 - xi-1 fi+1d + xi+1 - xi xi+1 - xi-1 fid , for ​ i=2,3,…,n-1 f1 = f2d - 1 2 (f2-f2d) fn = fnd - 1 2 (fn-1-fnd).$ (2)
If it is required, as a constraint, that these values should never be negative then a limiting filter is applied to $f$ as described in Section 3.6 of West (2011).
An ameliorated (smoothed) form of this linear interpolation for the forward rates is implemented using the amelioration (smoothing) parameter $\lambda$. For $\lambda \equiv 0$, equation (2) is used (with possible post-process filtering); for $0<\lambda \le 1$, the ameliorated method described fully in West (2011) is used.
The values computed by e01cef are used by e01cff to compute, for a given value $\stackrel{^}{x}$, the monotone convex interpolated (or extrapolated) value $\stackrel{^}{y}\left(\stackrel{^}{x}\right)$ and the corresponding instantaneous forward rate $f$; the curve gradient at $\stackrel{^}{x}$ can be derived as ${y}^{\prime }=\left(f-\stackrel{^}{y}\right)/\stackrel{^}{x}$ for $\stackrel{^}{x}\ne 0$.

## 4References

Hagan P S and West G (2006) Interpolation methods for curve construction Applied Mathematical Finance 13(2) 89–129
Hagan P S and West G (2008) Methods for constructing a yield curve WILLMOTT Magazine May 70–81
West G (2011) The monotone convex method of interpolation Financial Modelling Agency

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of data points.
Constraint: ${\mathbf{n}}\ge 2$.
2: $\mathbf{lam}$Real (Kind=nag_wp) Input
On entry: $\lambda$, the amelioration (smoothing) parameter. Forward rates are first computed using (2) and then, if $\lambda >0$, a limiting filter is applied which depends on neighbouring discrete forward values. This filter has a smoothing effect on the curve that increases with $\lambda$.
Suggested value: $\lambda =0.2$.
Constraint: $0.0\le {\mathbf{lam}}\le 1.0$.
3: $\mathbf{negfor}$Logical Input
On entry: determines whether or not to allow negative forward rates.
${\mathbf{negfor}}=\mathrm{.TRUE.}$
Negative forward rates are permitted.
${\mathbf{negfor}}=\mathrm{.FALSE.}$
Forward rates calculated must be non-negative.
4: $\mathbf{yfor}$Logical Input
On entry: determines whether the array y contains values, $y$, or discrete forward rates ${f}^{d}$.
${\mathbf{yfor}}=\mathrm{.TRUE.}$
y contains the discrete forward rates ${f}_{i}^{d}$, for $\mathit{i}=1,2,\dots ,n$.
${\mathbf{yfor}}=\mathrm{.FALSE.}$
y contains the values ${y}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
5: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: $x$, the (possibly unordered) set of data points.
6: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry:
If ${\mathbf{yfor}}=\mathrm{.TRUE.}$, the discrete forward rates ${f}_{i}^{d}$ corresponding to the data points ${x}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
If ${\mathbf{yfor}}=\mathrm{.FALSE.}$, the data values ${y}_{i}$ corresponding to the data points ${x}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
7: $\mathbf{comm}\left(4×{\mathbf{n}}+10\right)$Real (Kind=nag_wp) array Communication Array
On exit: contains information to be passed to e01cff. The information stored includes the discrete forward rates ${f}^{d}$, the instantaneous forward rates $f$, and the ordered data points $\xi$.
8: $\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{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{lam}}=⟨\mathit{\text{value}}⟩$.
Constraint: $0.0\le {\mathbf{lam}}\le 1.0$.
${\mathbf{ifail}}=3$
On entry, x contains duplicate data points.
${\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

The computational errors in the values stored in the array comm should be negligible in most practical situations.

## 8Parallelism and Performance

e01cef internally allocates $9n$ reals.