NAG Library Routine Document

g05xdf (bb_inc)

1
Purpose

g05xdf 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 routine g05xcf must be called prior to the first call to g05xdf.

2
Specification

Fortran Interface
Subroutine g05xdf ( npaths, rcord, d, a, diff, z, ldz, c, ldc, b, ldb, rcomm, ifail)
Integer, Intent (In):: npaths, rcord, d, a, ldz, ldc, ldb
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: diff(d), c(ldc,*), rcomm(*)
Real (Kind=nag_wp), Intent (Inout):: z(ldz,*), b(ldb,*)
C Header Interface
#include <nagmk26.h>
void  g05xdf_ (const Integer *npaths, const Integer *rcord, const Integer *d, const Integer *a, const double diff[], double z[], const Integer *ldz, const double c[], const Integer *ldc, double b[], const Integer *ldb, const double rcomm[], Integer *ifail)

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 g05xcf. 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 routine g05xcf.
1:     npaths – IntegerInput
On entry: the number of Wiener sample paths.
Constraint: npaths1.
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: rcord=1 or 2.
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:     diffd – Real (Kind=nag_wp) arrayInput
On entry: the difference between the terminal value and starting value of the Wiener process. If a=0, diff is ignored.
6:     zldz* – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array z must be at least npaths if rcord=1 and at least d×N+1-a if rcord=2.
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:     ldz – IntegerInput
On entry: the first dimension of the array z as declared in the (sub)program from which g05xdf is called.
Constraints:
  • if rcord=1, ldzd×N+1-a;
  • if rcord=2, ldznpaths.
8:     cldc* – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array c must be at least d.
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:     ldc – IntegerInput
On entry: the first dimension of the array c as declared in the (sub)program from which g05xdf is called.
Constraint: ldcd.
10:   bldb* – Real (Kind=nag_wp) arrayOutput
Note: the second dimension of the array b must be at least npaths if rcord=1 and at least d×N+1 if rcord=2.
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:   ldb – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which g05xdf is called.
Constraints:
  • if rcord=1, ldbd×N+1;
  • if rcord=2, ldbnpaths.
12:   rcomm* – Real (Kind=nag_wp) arrayCommunication Array
Note: the dimension 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 g05xcf or g05xdf.
On entry: communication array as returned by the last call to g05xcf or g05xdf. This array must not be directly modified.
13:   ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 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 argument, the recommended value is 0. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, rcomm was not initialized or has been corrupted.
ifail=2
On entry, npaths=value.
Constraint: npaths1.
ifail=3
On entry, rcord=value was an illegal value.
ifail=4
On entry, d=value.
Constraint: d1.
ifail=5
On entry, a=value.
Constraint: a=0​ or ​1.
ifail=6
On entry, ldz=value and d×ntimes+1-a=value.
Constraint: ldzd×ntimes+1-a.
On entry, ldz=value and npaths=value.
Constraint: ldznpaths.
ifail=7
On entry, ldc=value.
Constraint: ldcvalue.
ifail=8
On entry, ldb=value and d×ntimes+1=value.
Constraint: ldbd×ntimes+1.
On entry, ldb=value and npaths=value.
Constraint: ldbnpaths.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

Not applicable.

8
Parallelism and Performance

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

10.2
Program Data

None.

10.3
Program Results

Program Results (g05xdfe.r)