G05 Chapter Contents
G05 Chapter Introduction
NAG Library Manual

NAG Library Routine DocumentG05XBF

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

G05XBF uses a Brownian bridge algorithm to construct sample paths for a free or non-free Wiener process. The initialization routine G05XAF must be called prior to the first call to G05XBF.

2  Specification

 SUBROUTINE G05XBF ( NPATHS, RCORD, D, START, A, TERM, Z, LDZ, C, LDC, B, LDB, RCOMM, IFAIL)
 INTEGER NPATHS, RCORD, D, A, LDZ, LDC, LDB, IFAIL REAL (KIND=nag_wp) START(D), TERM(D), Z(LDZ,*), C(LDC,*), B(LDB,*), RCOMM(*)

3  Description

For details on the Brownian bridge algorithm and the bridge construction order see Section 2.6 in the G05 Chapter Introduction and Section 3 in G05XAF. Recall that the terms Wiener process (or free Wiener process) and Brownian motion are often used interchangeably, while a non-free Wiener process (also known as a Brownian bridge process) refers to a process which is forced to terminate at a given point.
Glasserman P (2004) Monte Carlo Methods in Financial Engineering Springer

5  Parameters

Note: the following variable is used in the parameter descriptions: $\mathit{N}={\mathbf{NTIMES}}$, the length of the array TIMES passed to the initialization routine G05XAF.
1:     NPATHS – INTEGERInput
On entry: the number of Wiener sample paths to create.
Constraint: ${\mathbf{NPATHS}}\ge 1$.
2:     RCORD – INTEGERInput
On entry: the order in which Normal random numbers are stored in Z and in which the generated values are returned in B.
Constraint: ${\mathbf{RCORD}}=1$ or $2$.
3:     D – INTEGERInput
On entry: the dimension of each Wiener sample path.
Constraint: ${\mathbf{D}}\ge 1$.
4:     START(D) – REAL (KIND=nag_wp) arrayInput
On entry: the starting value of the Wiener process.
5:     A – INTEGERInput
On entry: if ${\mathbf{A}}=0$, a free Wiener process is created beginning at START and TERM is ignored.
If ${\mathbf{A}}=1$, a non-free Wiener process is created beginning at START and ending at TERM.
Constraint: ${\mathbf{A}}=0$ or $1$.
6:     TERM(D) – REAL (KIND=nag_wp) arrayInput
On entry: the terminal value at which the non-free Wiener process should end. If ${\mathbf{A}}=0$, TERM is ignored.
7:     Z(LDZ,$*$) – REAL (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array Z must be at least ${\mathbf{NPATHS}}$ if ${\mathbf{RCORD}}=1$ and at least ${\mathbf{D}}×\left(\mathit{N}+1-{\mathbf{A}}\right)$ if ${\mathbf{RCORD}}=2$.
On entry: the Normal random numbers used to construct the sample paths.
If ${\mathbf{RCORD}}=1$ and quasi-random numbers are used, the ${\mathbf{D}}×\left(\mathit{N}+1-{\mathbf{A}}\right)$, where $\mathit{N}=\mathrm{nint}{\mathbf{RCOMM}}\left(2\right)$-dimensional quasi-random points should be stored in successive columns of Z.
If ${\mathbf{RCORD}}=2$ and quasi-random numbers are used, the ${\mathbf{D}}×\left(\mathit{N}+1-{\mathbf{A}}\right)$, where $\mathit{N}=\mathrm{nint}{\mathbf{RCOMM}}\left(2\right)$-dimensional quasi-random points should be stored in successive rows of Z.
On exit: the Normal random numbers premultiplied by C.
8:     LDZ – INTEGERInput
On entry: the first dimension of the array Z as declared in the (sub)program from which G05XBF is called.
Constraints:
• if ${\mathbf{RCORD}}=1$, ${\mathbf{LDZ}}\ge {\mathbf{D}}×\left(\mathit{N}+1-{\mathbf{A}}\right)$;
• if ${\mathbf{RCORD}}=2$, ${\mathbf{LDZ}}\ge {\mathbf{NPATHS}}$.
9:     C(LDC,$*$) – REAL (KIND=nag_wp) arrayInput
Note: the second dimension of the array C must be at least ${\mathbf{D}}$.
On entry: the lower triangular Cholesky factorization $C$ such that $C{C}^{\mathrm{T}}$ gives the covariance matrix of the Wiener process. Elements of C above the diagonal are not referenced.
10:   LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which G05XBF is called.
Constraint: ${\mathbf{LDC}}\ge {\mathbf{D}}$.
11:   B(LDB,$*$) – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array B must be at least ${\mathbf{NPATHS}}$ if ${\mathbf{RCORD}}=1$ and at least ${\mathbf{D}}×\left(\mathit{N}+1\right)$ if ${\mathbf{RCORD}}=2$.
On exit: the values of the Wiener sample paths.
Let ${X}_{p,i}^{k}$ denote the $k$th dimension of the $i$th point of the $p$th sample path where $1\le k\le {\mathbf{D}}$, $1\le i\le \mathit{N}+1$ and $1\le p\le {\mathbf{NPATHS}}$.
If ${\mathbf{RCORD}}=1$, the point ${X}_{p,i}^{k}$ will be stored at ${\mathbf{B}}\left(k+\left(i-1\right)×{\mathbf{D}},p\right)$.
If ${\mathbf{RCORD}}=2$, the point ${X}_{p,i}^{k}$ will be stored at ${\mathbf{B}}\left(p,k+\left(i-1\right)×{\mathbf{D}}\right)$.
The starting value START is never stored, whereas the terminal value is always stored.
12:   LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which G05XBF is called.
Constraints:
• if ${\mathbf{RCORD}}=1$, ${\mathbf{LDB}}\ge {\mathbf{D}}×\left(\mathit{N}+1\right)$;
• if ${\mathbf{RCORD}}=2$, ${\mathbf{LDB}}\ge {\mathbf{NPATHS}}$.
13:   RCOMM($*$) – REAL (KIND=nag_wp) arrayCommunication Array
On entry: communication array as returned by the last call to G05XAF or G05XBF. This array must not be directly modified.
14:   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, RCOMM was not initialized or has been corrupted. On entry, RCOMM was not initialized or has been corrupted. On entry, RCOMM was not initialized or has been corrupted.
${\mathbf{IFAIL}}=2$
On entry, ${\mathbf{NPATHS}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{NPATHS}}\ge 1$.
${\mathbf{IFAIL}}=3$
On entry, the value of RCORD is invalid.
${\mathbf{IFAIL}}=4$
On entry, ${\mathbf{D}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{D}}\ge 1$.
${\mathbf{IFAIL}}=5$
On entry, ${\mathbf{A}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{A}}=0\text{​ or ​}1$.
${\mathbf{IFAIL}}=6$
On entry, ${\mathbf{LDZ}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{D}}×\left({\mathbf{NTIMES}}+1-{\mathbf{A}}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDZ}}\ge {\mathbf{D}}×\left({\mathbf{NTIMES}}+1-{\mathbf{A}}\right)$.
On entry, ${\mathbf{LDZ}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{NPATHS}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDZ}}\ge {\mathbf{NPATHS}}$.
${\mathbf{IFAIL}}=7$
On entry, ${\mathbf{LDC}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDC}}\ge ⟨\mathit{\text{value}}⟩$.
${\mathbf{IFAIL}}=8$
On entry, ${\mathbf{LDB}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{D}}×\left({\mathbf{NTIMES}}+1\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDB}}\ge {\mathbf{D}}×\left({\mathbf{NTIMES}}+1\right)$.
On entry, ${\mathbf{LDB}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{NPATHS}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDB}}\ge {\mathbf{NPATHS}}$.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.

Not applicable.

None.

9  Example

This example calls G05XBF, G05XAF and G05XEF to generate two sample paths of a three dimensional non-free Wiener process. The process starts at zero and each sample path terminates at the point $\left(1.0,0.5,0.0\right)$. Quasi-random numbers are used to construct the sample paths.
See Section 9 in G05XAF and G05XEF for additional examples.

9.1  Program Text

Program Text (g05xbfe.f90)

None.

9.3  Program Results

Program Results (g05xbfe.r)