nag_rand_bb (g05xbc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_rand_bb (g05xbc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg05.h>
void  nag_rand_bb (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)

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 nag_rand_bb_init (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.

4  References

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

5  Arguments

Note: the following variable is used in the parameter descriptions: N=ntimes, the length of the array times passed to the initialization function nag_rand_bb_init (g05xac).
1:     orderNag_OrderTypeInput
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 order=Nag_RowMajor. See Section in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     npathsIntegerInput
On entry: the number of Wiener sample paths to create.
Constraint: npaths1.
3:     dIntegerInput
On entry: the dimension of each Wiener sample path.
Constraint: d1.
4:     start[d]const doubleInput
On entry: the starting value of the Wiener process.
5:     aIntegerInput
On entry: if a=0, a free Wiener process is created beginning at start and term is ignored.
If a=1, a non-free Wiener process is created beginning at start and ending at term.
Constraint: a=0 or 1.
6:     term[d]const doubleInput
On entry: the terminal value at which the non-free Wiener process should end. If a=0, term is ignored.
7:     z[dim]doubleInput/Output
Note: the dimension, dim, of the array z must be at least
  • pdz×npaths when order=Nag_RowMajor;
  • pdz×(d×N+1-a) when order=Nag_ColMajor.
The i,jth element of the matrix Z is stored in
  • z[j-1×pdz+i-1] when order=Nag_ColMajor;
  • z[i-1×pdz+j-1] when order=Nag_RowMajor.
On entry: the Normal random numbers used to construct the sample paths.
If quasi-random numbers are used, the d×N+1-a-dimensional quasi-random points should be stored in successive rows of Z.
On exit: the Normal random numbers premultiplied by C.
8:     pdzIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array z.
  • if order=Nag_RowMajor, pdzd×N+1-a;
  • if order=Nag_ColMajor, pdznpaths.
9:     c[dim]const doubleInput
Note: the dimension, dim, of the array c must be at least pdc×d.
The i,jth element of the matrix C is stored in c[j-1×pdc+i-1].
On entry: the lower triangular Cholesky factorization C such that CCT gives the covariance matrix of the Wiener process. Elements of C above the diagonal are not referenced.
10:   pdcIntegerInput
On entry: the stride separating matrix row elements in the array c.
Constraint: pdcd.
11:   b[dim]doubleOutput
Note: the dimension, dim, of the array b must be at least
  • pdb×npaths when order=Nag_RowMajor;
  • pdb×(d×N+1) when order=Nag_ColMajor.
The i,jth element of the matrix B is stored in
  • b[j-1×pdb+i-1] when order=Nag_ColMajor;
  • b[i-1×pdb+j-1] when order=Nag_RowMajor.
On exit: the values of the Wiener sample paths.
Let Xp,ik denote the kth dimension of the ith point of the pth sample path where 1kd, 1iN+1 and 1pnpaths. The point Xp,ik is stored at Bp,k+i-1×d. The starting value start is never stored, whereas the terminal value is always stored.
12:   pdbIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array b.
  • if order=Nag_RowMajor, pdbd×N+1;
  • if order=Nag_ColMajor, pdbnpaths.
13:   rcomm[dim]const doubleCommunication Array
Note: the dimension, 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 nag_rand_bb_init (g05xac) or nag_rand_bb (g05xbc).
On entry: communication array as returned by the last call to nag_rand_bb_init (g05xac) or nag_rand_bb (g05xbc). This array MUST NOT be directly modified.
14:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

Dynamic memory allocation failed.
On entry, pdb=value and d×ntimes+1=value.
Constraint: pdbd×ntimes+1.
On entry, pdb=value and npaths=value.
Constraint: pdbnpaths.
On entry, pdc=value.
Constraint: pdcvalue.
On entry, pdz=value and d×ntimes+1-a=value.
Constraint: pdzd×ntimes+1-a.
On entry, pdz=value and npaths=value.
Constraint: pdznpaths.
On entry, argument value had an illegal value.
On entry, rcomm was not initialized or has been corrupted.
On entry, a=value.
Constraint: a=0​ or ​1.
On entry, d=value.
Constraint: d1.
On entry, npaths=value.
Constraint: npaths1.
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.

7  Accuracy

Not applicable.

8  Parallelism and Performance

nag_rand_bb (g05xbc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_rand_bb (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 Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments


10  Example

This example calls nag_rand_bb (g05xbc), nag_rand_bb_init (g05xac) and nag_rand_bb_make_bridge_order (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 1.0,0.5,0.0. Quasi-random numbers are used to construct the sample paths.
See Section 10 in nag_rand_bb_init (g05xac) and nag_rand_bb_make_bridge_order (g05xec) for additional examples.

10.1  Program Text

Program Text (g05xbce.c)

10.2  Program Data


10.3  Program Results

Program Results (g05xbce.r)

nag_rand_bb (g05xbc) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2014