NAG FL Interface
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 <nag.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) |
|
C++ Header Interface
#include <nag.h> extern "C" {
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) |
}
|
The routine may be called by the names g05xdf or nagf_rand_bb_inc.
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 , let be any set of time points satisfying , and let , , denote a -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
, and then uses this to compute the
scaled Wiener increments
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:
, the length of the array
times passed to the initialization routine
g05xcf.
-
1:
– Integer
Input
-
On entry: the number of Wiener sample paths.
Constraint:
.
-
2:
– Integer
Input
-
On entry: the order in which Normal random numbers are stored in
z and in which the generated values are returned in
b.
Constraint:
or .
-
3:
– Integer
Input
-
On entry: the dimension of each Wiener sample path.
Constraint:
.
-
4:
– Integer
Input
-
On entry: if
, a free Wiener process is created and
diff is ignored.
If
, a non-free Wiener process is created where
diff is the difference between the terminal value and the starting value of the process.
Constraint:
or .
-
5:
– Real (Kind=nag_wp) array
Input
-
On entry: the difference between the terminal value and starting value of the Wiener process. If
,
diff is ignored.
-
6:
– Real (Kind=nag_wp) array
Input/Output
-
Note: the second dimension of the array
z
must be at least
if
and at least
if
.
On entry: the Normal random numbers used to construct the sample paths.
If quasi-random numbers are used, the -dimensional quasi-random points should be stored in successive rows of .
On exit: the Normal random numbers premultiplied by
c.
-
7:
– Integer
Input
-
On entry: the first dimension of the array
z as declared in the (sub)program from which
g05xdf is called.
Constraints:
- if , ;
- if , .
-
8:
– Real (Kind=nag_wp) array
Input
-
Note: the second dimension of the array
c
must be at least
.
On entry: the lower triangular Cholesky factorization such that gives the covariance matrix of the Wiener process. Elements of above the diagonal are not referenced.
-
9:
– Integer
Input
-
On entry: the first dimension of the array
c as declared in the (sub)program from which
g05xdf is called.
Constraint:
.
-
10:
– Real (Kind=nag_wp) array
Output
-
Note: the second dimension of the array
b
must be at least
if
and at least
if
.
On exit: the scaled Wiener increments.
Let denote the th dimension of the th point of the th sample path where , and . The increment is stored at .
-
11:
– Integer
Input
-
On entry: the first dimension of the array
b as declared in the (sub)program from which
g05xdf is called.
Constraints:
- if , ;
- if , .
-
12:
– Real (Kind=nag_wp) array
Communication 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:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry,
rcomm was not initialized or has been corrupted.
-
On entry, .
Constraint: .
-
On entry, was an illegal value.
-
On entry, .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
-
On entry, .
Constraint: .
-
On entry, and .
Constraint: .
On entry, and .
Constraint: .
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface 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.
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
on the interval
where
is a (free or non-free) Wiener process and
and
are suitable functions. A numerical solution to this SDE can be obtained by the Euler–Maruyama method. For any discretization
of
, set
for
so that
is an approximation to
. The scaled Wiener increments produced by
g05xdf can be used in the
Euler–Maruyama scheme outlined above by writing
The following example program uses this method to solve the SDE for geometric Brownian motion
where
is a Wiener process, and compares the results against the analytic solution
Quasi-random variates are used to construct the Wiener increments.
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results