|
Calling Sequence
|
|
SamplePath(expression, t = timeinterval, opts)
SamplePath(pathgenerator, opts)
SamplePath(process, timegrid, opts)
SamplePath(process, timeinterval, opts)
SamplePath(transform, pathgenerator, opts)
SamplePath(d, transform, pathgenerator, opts)
|
|
Parameters
|
|
expression
|
-
|
algebraic expression; expression whose sample path is to be generated
|
t
|
-
|
name; time variable for use in expression
|
timeinterval
|
-
|
range; time interval
|
pathgenerator
|
-
|
path generator data structure; path generator
|
process
|
-
|
one- or multi-dimensional stochastic process, or list or vector of one-dimensional stochastic processes
|
timegrid
|
-
|
list, Vector or time grid data structure; time grid
|
transform
|
-
|
procedure; path function
|
d
|
-
|
positive integer; dimension of the new process
|
opts
|
-
|
(optional) equation(s) of the form option = value where option is one of replications or timesteps; specify options for the SamplePath command
|
|
|
|
|
Options
|
|
•
|
replications = posint -- This option specifies the number of replications of the sample path. By default, only one replication of the sample path is generated.
|
•
|
timesteps = posint -- This option specifies the number of time steps. This option is ignored if explicit time grid is specified. By default, only one time step is used.
|
|
|
Description
|
|
•
|
The SamplePath command generates sample paths for a given stochastic process. This command can handle one- as well as multi-dimensional processes.
|
•
|
In the one-dimensional case, the value returned by SamplePath is a matrix of size , where is the requested number of replications of the sample path (see the replications option) and is the number of points in the time grid (the number of time steps plus one). Each row of this matrix is a single realization of the sample path of the stochastic process of interest. In the multi-dimensional case, the value returned by SamplePath is a matrix of size , where and are the same as in the one-dimensional case, and is the dimension of the stochastic process to be simulated, which is either given explicitly or deduced from the dimension of the underlying stochastic process.
|
•
|
The SamplePath(expression, t = timeinterval, opts) calling sequence attempts to extract all the stochastic variables involved in expression and generate the corresponding path generator and path function using the time grid or the specified number of time steps. In this case, only a one-dimensional path can be generated. The parameter timeinterval must be of type range , where and are non-negative constants such that .
|
|
Note that if , the value at will be simulated using a single step of the default discretization method and hence can suffer from a significant discretization bias. Increasing the number of time steps will refine the grid between and , but will have no effect on the value at . To reduce the bias, use a time interval of the form . All stochastic variables involved in expression should be of the form . If is multi-dimensional stochastic, then the individual components of can be accessed using the notation .
|
•
|
The SamplePath(pathgenerator, opts) calling sequence generates the specified number of replications of the sample path using the path generator pathgenerator. For more details, see Finance[PathGenerator].
|
•
|
The SamplePath(transform, pathgenerator, opts) calling sequence generates sample paths for a certain one-dimensional stochastic process given a path generator pathgenerator and a procedure transform that converts paths generated by pathgenerator to paths of the stochastic process of interest. Note that pathgenerator can be multi-dimensional.
|
•
|
To generate a single realization of the sample path of interest, SamplePath generates a sample path for the base stochastic process using the path generator pathgenerator and stores these values as an Array, for example . If pathgenerator is one-dimensional, is a one-dimensional array of size . If pathgenerator is multi-dimensional, is a two-dimensional array of size , where is the dimension of pathgenerator. Then SamplePath evaluates , where is a preallocated one-dimensional floating-point array of the same size as . The values stored in are used as the new replication of the sample path and stored as a row in the resulting matrix. This process will be repeated for the specified number of replications.
|
•
|
The SamplePath(d, transform, pathgenerator, opts) calling sequence uses the same method, but with a multi-dimensional process. Therefore, is now of size . Note the difference between the SamplePath(transform, pathgenerator, opts) and SamplePath(1, transform, pathgenerator, opts) calling sequences. The first returns an array of size , while the other returns an array of size .
|
•
|
The SamplePath command uses the Maple random number generator (see RandomTools[MersenneTwister]) to generate the intermediate random numbers required by the corresponding algorithm. As a consequence, all values generated by SamplePath are deterministic, meaning the same values are generated every Maple session. Use randomize or RandomTools[MersenneTwister][SetState] to randomize the state of the internal random number generator.
|
|
|
Examples
|
|
>
|
|
>
|
|
Create 20 replications of the sample path of on the interval using time steps.
>
|
|
Here is a single realization of the sample path.
Here is an example involving a two-dimensional process.
>
|
|
Create path generators for and on the interval and use them to generate sample paths for and .
>
|
|
>
|
|
>
|
|
>
|
|
Here are realizations of the sample paths.
Use the above path generator to generate sample paths for the process .
>
|
f := proc(B, A) local d, i; d := rtable_dims(A); for i from lhs(d) to rhs(d) do B[i] := exp(A[i]) end do; end proc;
|
| (1) |
>
|
|
Simulate the one-dimensional process where is the previously defined two-dimensional Wiener process.
>
|
f2 := proc(B, A) local d, i; d := rtable_dims(A)[2]; for i from lhs(d) to rhs(d) do B[i] := A[1, i]+A[2, i] end do; end proc:
|
>
|
|
This is the same example using the last calling sequence. Note the difference between procedures and .
>
|
F2 := proc(B, A) local d, i; d := rtable_dims(A)[2]; for i from lhs(d) to rhs(d) do B[1, i] := A[1, i] + A[2, i]; end do; end proc:
|
>
|
|
Simulate the three-dimensional process where is the same two-dimensional Wiener process.
>
|
F := proc(B, A) local d, i; d := rtable_dims(A)[2]; for i from lhs(d) to rhs(d) do B[1, i] := A[1, i]; B[2, i] := A[2, i]; B[3, i] := A[1, i] + A[2, i]; end do; end proc:
|
>
|
|
Simulate an expression involving the stochastic variable just defined. Call SamplePath using two different forms: algebraic and procedural. To check for consistency, save the state of the Maple random number generator and restore this state before the second simulation.
>
|
|
Use the same state of the random number generator to compare the results.
>
|
|
>
|
|
This is the same example as above but using a Maple procedure.
>
|
|
>
|
f := proc(B, A) local i; for i from 1 to 11 do B[i] := A[i]^2; end do; end proc:
|
>
|
|
This is the same example using an explicitly defined time grid.
>
|
|
This is a multi-dimensional path that depends on one stochastic factor.
>
|
|
This is a multivariate stochastic process.
>
|
|
>
|
|
>
|
|
Here is the first replication of the sample path.
| (5) |
Here is an example of a stochastic process that depends on two factors: one is the previously defined Wiener process; the second is a Poisson process.
>
|
|
>
|
|
Here are some expressions involving stochastic variables.
| (8) |
>
|
|
| (9) |
>
|
|
>
|
|
| (10) |
>
|
|
Here is the use of a path function.
>
|
testproc := proc(Y, X) local i; for i from 1 to 11 do Y[i] := exp(X[i]); end do; end proc:
|
>
|
|
>
|
|
|
|
References
|
|
|
Glasserman, P., Monte Carlo Methods in Financial Engineering. New York: Springer-Verlag, 2004.
|
|
Hull, J., Options, Futures, and Other Derivatives, 5th. edition. Upper Saddle River, New Jersey: Prentice Hall, 2003.
|
|
Kloeden, P., and Platen, E., Numerical Solution of Stochastic Differential Equations, New York: Springer-Verlag, 1999.
|
|
|
Compatibility
|
|
•
|
The Finance[SamplePath] command was introduced in Maple 15.
|
|
|
|