NAG C Library Function Document

nag_rand_bb_inc (g05xdc)

1
Purpose

nag_rand_bb_inc (g05xdc) computes scaled increments of sample paths of a free or non-free Wiener process, where the sample paths are constructed by a Brownian bridge algorithm. The initialization function nag_rand_bb_inc_init (g05xcc) must be called prior to the first call to nag_rand_bb_inc (g05xdc).

2
Specification

#include <nag.h>
#include <nagg05.h>
void  nag_rand_bb_inc (Nag_OrderType order, Integer npaths, Integer d, Integer a, const double diff[], 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_inc_init (g05xcc). 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.
Fix two times t0<T, let ti 1iN  be any set of time points satisfying t0<t1<t2<<tN<T, and let Xt0, Xti 1iN , XT denote a d-dimensional Wiener sample path at these time points.
The Brownian bridge increments generator uses the Brownian bridge algorithm to construct sample paths for the (free or non-free) Wiener process X, and then uses this to compute the scaled Wiener increments
Xt1 - Xt0 t1 - t0 , Xt2 - Xt1 t2 - t1 ,, XtN - XtN-1 tN - tN-1 , XT - XtN T - tN  
The example program in Section 10 shows how these increments can be used to compute a numerical solution to a stochastic differential equation (SDE) driven by a (free or non-free) Wiener process.

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_inc_init (g05xcc).
1:     order Nag_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 3.3.1.3 in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     npaths IntegerInput
On entry: the number of Wiener sample paths.
Constraint: npaths1.
3:     d IntegerInput
On entry: the dimension of each Wiener sample path.
Constraint: d1.
4:     a IntegerInput
On entry: if a=0, a free Wiener process is created and diff is ignored.
If a=1, a non-free Wiener process is created where diff is the difference between the terminal value and the starting value of the process.
Constraint: a=0 or 1.
5:     diff[d] const doubleInput
On entry: the difference between the terminal value and starting value of the Wiener process. If a=0, diff is ignored.
6:     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.
7:     pdz IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array z.
Constraints:
  • if order=Nag_RowMajor, pdzd×N+1-a;
  • if order=Nag_ColMajor, pdznpaths.
8:     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.
9:     pdc IntegerInput
On entry: the stride separating matrix row elements in the array c.
Constraint: pdcd.
10:   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 scaled Wiener increments.
Let Xp,ik denote the kth dimension of the ith point of the pth sample path where 1kd, 1iN+1 and 1pnpaths. The increment Xp,ik-Xp,i-1kti-ti-1 is stored at Bp,k+i-1×d.
11:   pdb IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array b.
Constraints:
  • if order=Nag_RowMajor, pdbd×N+1;
  • if order=Nag_ColMajor, pdbnpaths.
12:   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_inc_init (g05xcc) or nag_rand_bb_inc (g05xdc).
On entry: communication array as returned by the last call to nag_rand_bb_inc_init (g05xcc) or nag_rand_bb_inc (g05xdc). This array MUST NOT be directly modified.
13:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_ARRAY_SIZE
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.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_ILLEGAL_COMM
On entry, rcomm was not initialized or has been corrupted.
NE_INT
On entry, a=value.
Constraint: a=0​ or ​1.
On entry, d=value.
Constraint: d1.
On entry, npaths=value.
Constraint: npaths1.
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 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

Not applicable.

8
Parallelism and Performance

nag_rand_bb_inc (g05xdc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_rand_bb_inc (g05xdc) 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.

9
Further Comments

None.

10
Example

The scaled Wiener increments produced by this function can be used to compute numerical solutions to stochastic differential equations (SDEs) driven by (free or non-free) Wiener processes. Consider an SDE of the form
d Yt = ft,Yt dt + σt,Yt dXt  
on the interval t0,T  where Xt t0 tT  is a (free or non-free) Wiener process and f and σ are suitable functions. A numerical solution to this SDE can be obtained by the Euler–Maruyama method. For any discretization t0 < t1 < t2 << tN+1=T  of t0,T , set
Y ti+1 = Y ti + f ti,Yti ti+1 - ti + σ ti,Yti Xti+1 - Xti  
for i=1,,N so that YtN+1  is an approximation to YT. The scaled Wiener increments produced by nag_rand_bb_inc (g05xdc) can be used in the Euler–Maruyama scheme outlined above by writing
Yti+1 = Yti + ti+1 - ti f ti,Yti + σ ti,Yti Xti+1 - Xti ti+1 - ti .  
The following example program uses this method to solve the SDE for geometric Brownian motion
d St = rSt dt + σSt dXt  
where X is a Wiener process, and compares the results against the analytic solution
ST = S0 exp r-σ2/2 T + σXT .  
Quasi-random variates are used to construct the Wiener increments.

10.1
Program Text

Program Text (g05xdce.c)

10.2
Program Data

None.

10.3
Program Results

Program Results (g05xdce.r)