# NAG CL Interfaceg05xbc (bb)

Settings help

CL Name Style:

## 1Purpose

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

## 2Specification

 #include
 void g05xbc (Nag_OrderType order, Integer npaths, Integer d, const double start[], Integer a, const double term[], double z[], Integer pdz, const double c[], Integer pdc, double b[], Integer pdb, const double rcomm[], NagError *fail)
The function may be called by the names: g05xbc or nag_rand_bb.

## 3Description

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 g05xac. 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.

## 4References

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

## 5Arguments

Note: the following variable is used in the parameter descriptions: $\mathit{N}={\mathbf{ntimes}}$, the length of the array times passed to the initialization function g05xac.
1: $\mathbf{order}$Nag_OrderType Input
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2: $\mathbf{npaths}$Integer Input
On entry: the number of Wiener sample paths to create.
Constraint: ${\mathbf{npaths}}\ge 1$.
3: $\mathbf{d}$Integer Input
On entry: the dimension of each Wiener sample path.
Constraint: ${\mathbf{d}}\ge 1$.
4: $\mathbf{start}\left[{\mathbf{d}}\right]$const double Input
On entry: the starting value of the Wiener process.
5: $\mathbf{a}$Integer Input
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: $\mathbf{term}\left[{\mathbf{d}}\right]$const double Input
On entry: the terminal value at which the non-free Wiener process should end. If ${\mathbf{a}}=0$, term is ignored.
7: $\mathbf{z}\left[\mathit{dim}\right]$double Input/Output
Note: the dimension, dim, of the array z must be at least
• ${\mathbf{pdz}}×{\mathbf{npaths}}$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• ${\mathbf{pdz}}×\left({\mathbf{d}}×\left(\mathit{N}+1-{\mathbf{a}}\right)\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$.
The $\left(i,j\right)$th element of the matrix $Z$ is stored in
• ${\mathbf{z}}\left[\left(j-1\right)×{\mathbf{pdz}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{z}}\left[\left(i-1\right)×{\mathbf{pdz}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the Normal random numbers used to construct the sample paths.
If quasi-random numbers are used, the ${\mathbf{d}}×\left(\mathit{N}+1-{\mathbf{a}}\right)$-dimensional quasi-random points should be stored in successive rows of $Z$.
On exit: the Normal random numbers premultiplied by $C$.
8: $\mathbf{pdz}$Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array z.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdz}}\ge {\mathbf{d}}×\left(\mathit{N}+1-{\mathbf{a}}\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdz}}\ge {\mathbf{npaths}}$.
9: $\mathbf{c}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array c must be at least ${\mathbf{pdc}}×{\mathbf{d}}$.
The $\left(i,j\right)$th element of the matrix $C$ is stored in ${\mathbf{c}}\left[\left(j-1\right)×{\mathbf{pdc}}+i-1\right]$.
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: $\mathbf{pdc}$Integer Input
On entry: the stride separating matrix row elements in the array c.
Constraint: ${\mathbf{pdc}}\ge {\mathbf{d}}$.
11: $\mathbf{b}\left[\mathit{dim}\right]$double Output
Note: the dimension, dim, of the array b must be at least
• ${\mathbf{pdb}}×{\mathbf{npaths}}$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$;
• ${\mathbf{pdb}}×\left({\mathbf{d}}×\left(\mathit{N}+1\right)\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$.
where ${\mathbf{B}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{b}}\left[\left(j-1\right)×{\mathbf{pdb}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{b}}\left[\left(i-1\right)×{\mathbf{pdb}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
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}}$. The point ${X}_{p,i}^{k}$ is stored at $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: $\mathbf{pdb}$Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array b.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdb}}\ge {\mathbf{d}}×\left(\mathit{N}+1\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdb}}\ge {\mathbf{npaths}}$.
13: $\mathbf{rcomm}\left[\mathit{dim}\right]$const double Communication Array
Note: the dimension, $\mathit{dim}$, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument rcomm in the previous call to g05xac or g05xbc.
On entry: communication array as returned by the last call to g05xac or g05xbc. This array MUST NOT be directly modified.
14: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_ARRAY_SIZE
On entry, ${\mathbf{pdb}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{d}}×\left({\mathbf{ntimes}}+1\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdb}}\ge {\mathbf{d}}×\left({\mathbf{ntimes}}+1\right)$.
On entry, ${\mathbf{pdb}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{npaths}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdb}}\ge {\mathbf{npaths}}$.
On entry, ${\mathbf{pdc}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdc}}\ge ⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{pdz}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{d}}×\left({\mathbf{ntimes}}+1-{\mathbf{a}}\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdz}}\ge {\mathbf{d}}×\left({\mathbf{ntimes}}+1-{\mathbf{a}}\right)$.
On entry, ${\mathbf{pdz}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{npaths}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdz}}\ge {\mathbf{npaths}}$.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_ILLEGAL_COMM
On entry, rcomm was not initialized or has been corrupted.
NE_INT
On entry, ${\mathbf{a}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{a}}=0\text{​ or ​}1$.
On entry, ${\mathbf{d}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{d}}\ge 1$.
On entry, ${\mathbf{npaths}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{npaths}}\ge 1$.
On entry, the value of order is invalid.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.

Not applicable.

## 8Parallelism and Performance

g05xbc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g05xbc makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

This example calls g05xbc, g05xac and g05xec 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 10 in g05xac and g05xec for additional examples.

### 10.1Program Text

Program Text (g05xbce.c)

None.

### 10.3Program Results

Program Results (g05xbce.r)