G05 Chapter Contents
G05 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG05XAF

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.

## 1  Purpose

G05XAF initializes the Brownian bridge generator G05XBF. It must be called before any calls to G05XBF.

## 2  Specification

 SUBROUTINE G05XAF ( T0, TEND, TIMES, NTIMES, RCOMM, IFAIL)
 INTEGER NTIMES, IFAIL REAL (KIND=nag_wp) T0, TEND, TIMES(NTIMES), RCOMM(12*(NTIMES+1))

## 3  Description

### 3.1  Brownian Bridge Algorithm

Details on the Brownian bridge algorithm and the Brownian bridge process (sometimes also called a non-free Wiener process) can be found in Section 2.6 in the G05 Chapter Introduction. We briefly recall some notation and definitions.
Fix two times ${t}_{0} and let ${\left({t}_{i}\right)}_{1\le i\le N}$ be any set of time points satisfying ${t}_{0}<{t}_{1}<{t}_{2}<\cdots <{t}_{N}. Let ${\left({X}_{{t}_{i}}\right)}_{1\le i\le N}$ denote a $d$-dimensional Wiener sample path at these time points, and let $C$ be any $d$ by $d$ matrix such that $C{C}^{\mathrm{T}}$ is the desired covariance structure for the Wiener process. Each point ${X}_{{t}_{i}}$ of the sample path is constructed according to the Brownian bridge interpolation algorithm (see Glasserman (2004) or Section 2.6 in the G05 Chapter Introduction). We always start at some fixed point ${X}_{{t}_{0}}=x\in {ℝ}^{d}$. If we set ${X}_{T}=x+C\sqrt{T-{t}_{0}}Z$ where $Z$ is any $d$-dimensional standard Normal random variable, then $X$ will behave like a normal (free) Wiener process. However if we fix the terminal value ${X}_{T}=w\in {ℝ}^{d}$, then $X$ will behave like a non-free Wiener process.

### 3.2  Implementation

Given the start and end points of the process, the order in which successive interpolation times ${t}_{j}$ are chosen is called the bridge construction order. The construction order is given by the array TIMES. Further information on construction orders is given in Section 2.6.2 in the G05 Chapter Introduction. For clarity we consider here the common scenario where the Brownian bridge algorithm is used with quasi-random points. If pseudorandom numbers are used instead, these details can be ignored.
Suppose we require $P$ Wiener sample paths each of dimension $d$. The main input to the Brownian bridge algorithm is then an array of quasi-random points ${Z}^{1},{Z}^{2},\dots ,{Z}^{P}$ where each point ${Z}^{p}=\left({Z}_{1}^{p},{Z}_{2}^{p},\dots ,{Z}_{D}^{p}\right)$ has dimension $D=d\left(N+1\right)$ or $D=dN$ respectively, depending on whether a free or non-free Wiener process is required. When G05XBF is called, the $p$th sample path for $1\le p\le P$ is constructed as follows: if a non-free Wiener process is required set ${X}_{T}$ equal to the terminal value $w$, otherwise construct ${X}_{T}$ as
 $XT = Xt0 + C T-t0 Z1p ⋮ Zdp$
where $C$ is the matrix described in Section 3.1. The array TIMES holds the remaining time points ${t}_{1},{t}_{2},\dots {t}_{N}$ in the order in which the bridge is to be constructed. For each $j=1,\dots ,N$ set $r={\mathbf{TIMES}}\left(j\right)$, find
 $q = max t0, TIMESi : 1≤i
and
 $s = min T, TIMESi : 1≤i r$
and construct the point ${X}_{r}$ as
 $Xr = Xq s-r + Xs r-q s-q + C s-r r-q s-q Zjd-ad+1p ⋮ Zjd-ad+dp$
where $a=0$ or $a=1$ respectively depending on whether a free or non-free Wiener process is required. Note that in our discussion $j$ is indexed from $1$, and so ${X}_{r}$ is interpolated between the nearest (in time) Wiener points which have already been constructed. The routine G05XEF can be used to initialize the TIMES array for several predefined bridge construction orders.

## 4  References

Glasserman P (2004) Monte Carlo Methods in Financial Engineering Springer

## 5  Parameters

1:     T0 – REAL (KIND=nag_wp)Input
On entry: the starting value ${t}_{0}$ of the time interval.
2:     TEND – REAL (KIND=nag_wp)Input
On entry: the end value $T$ of the time interval.
Constraint: ${\mathbf{TEND}}>{\mathbf{T0}}$.
3:     TIMES(NTIMES) – REAL (KIND=nag_wp) arrayInput
On entry: the points in the time interval $\left({t}_{0},T\right)$ at which the Wiener process is to be constructed. The order in which points are listed in TIMES determines the bridge construction order. The routine G05XEF can be used to create predefined bridge construction orders from a set of input times.
Constraints:
• ${\mathbf{T0}}<{\mathbf{TIMES}}\left(\mathit{i}\right)<{\mathbf{TEND}}$, for $\mathit{i}=1,2,\dots ,{\mathbf{NTIMES}}$;
• ${\mathbf{TIMES}}\left(i\right)\ne {\mathbf{TIMES}}\left(j\right)$, for $i,j=1,2,\dots {\mathbf{NTIMES}}$ and $i\ne j$.
4:     NTIMES – INTEGERInput
On entry: the length of TIMES, denoted by $N$ in Section 3.1.
Constraint: ${\mathbf{NTIMES}}\ge 1$.
5:     RCOMM($12×\left({\mathbf{NTIMES}}+1\right)$) – REAL (KIND=nag_wp) arrayCommunication Array
On exit: communication array, used to store information between calls to G05XBF. This array must not be directly modified.
6:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{TEND}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{T0}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{TEND}}>{\mathbf{T0}}$.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{NTIMES}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{NTIMES}}\ge 1$.
${\mathbf{IFAIL}}=3$
On entry, ${\mathbf{TIMES}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$, ${\mathbf{T0}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{TEND}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{T0}}<{\mathbf{TIMES}}\left(i\right)<{\mathbf{TEND}}$ for all $i$.
${\mathbf{IFAIL}}=4$
On entry, ${\mathbf{TIMES}}\left(i\right)={\mathbf{TIMES}}\left(j\right)=⟨\mathit{\text{value}}⟩$ for $i=⟨\mathit{\text{value}}⟩$ and $j=⟨\mathit{\text{value}}⟩$.
Constraint: all elements of TIMES must be unique.

## 7  Accuracy

Not applicable.

The efficient implementation of a Brownian bridge algorithm requires the use of a workspace array called the working stack. Since previously computed points will be used to interpolate new points, they should be kept close to the hardware processing units so that the data can be accessed quickly. Ideally the whole stack should be held in hardware cache. Different bridge construction orders may require different amounts of working stack. Indeed, a naive bridge algorithm may require a stack of size $\frac{N}{4}$ or even $\frac{N}{2}$, which could be very inefficient when $N$ is large. G05XAF performs a detailed analysis of the bridge construction order specified by TIMES. Heuristics are used to find an execution strategy which requires a small working stack, while still constructing the bridge in the order required.

## 9  Example

This example calls G05XAF, G05XBF and G05XEF to generate two sample paths of a three dimensional free Wiener process. Pseudorandom variates are used to construct the sample paths.
See Section 9 in G05XBF and G05XEF for additional examples.

### 9.1  Program Text

Program Text (g05xafe.f90)

None.

### 9.3  Program Results

Program Results (g05xafe.r)