Finance[SamplePath] - generate sample path(s) for a stochastic process
|
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
|
|
|
|
|
Description
|
|
•
|
The SamplePath command generates sample paths for a given stochastic process. This command can handle one- as well as multi-dimensional processes.
|
•
|
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.
|
•
|
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.
|
|
|
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.
|
|
|
Compatibility
|
|
•
|
The Finance[SamplePath] command was introduced in Maple 15.
|
|
|
Examples
|
|
>
|
|
>
|
|
>
|
|
Create 20 replications of the sample path of on the interval using time steps.
>
|
|
| (1) |
Here is a single realization of the sample path.
>
|
|
| (2) |
Here is an example involving a two-dimensional process.
>
|
|
| (3) |
>
|
|
| (4) |
Create path generators for and on the interval and use them to generate sample paths for and .
>
|
|
>
|
|
| (5) |
>
|
|
>
|
|
| (6) |
Here are realizations of the sample paths.
>
|
|
| (7) |
>
|
|
| (8) |
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;
|
| (9) |
>
|
|
| (10) |
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:
|
>
|
|
| (11) |
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:
|
>
|
|
| (12) |
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:
|
>
|
|
| (13) |
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.
>
|
|
>
|
|
| (14) |
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:
|
>
|
|
| (15) |
This is the same example using an explicitly defined time grid.
>
|
|
| (16) |
This is a multi-dimensional path that depends on one stochastic factor.
>
|
|
| (17) |
This is a multivariate stochastic process.
>
|
|
| (18) |
>
|
|
| (19) |
>
|
|
| (20) |
>
|
|
| (21) |
Here is the first replication of the sample path.
>
|
|
| (22) |
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.
>
|
|
| (23) |
>
|
|
| (24) |
>
|
|
Here are some expressions involving stochastic variables.
>
|
|
| (25) |
>
|
|
| (26) |
>
|
|
| (27) |
>
|
|
| (28) |
>
|
|
| (29) |
>
|
|
| (30) |
Here is the use of a path function.
>
|
testproc := proc(Y, X) for i from 1 to 11 do Y[i] := exp(X[i]); end do; end proc:
|
Warning, `i` is implicitly declared local to procedure `testproc`
| |
>
|
|
| (31) |
>
|
|
|
|
See Also
|
|
Finance[BrownianMotion], Finance[CEVProcess], Finance[DeterministicProcess], Finance[Diffusion], Finance[Drift], Finance[ExpectedValue], Finance[GaussianShortRateProcess], Finance[GeometricBrownianMotion], Finance[HestonProcess], Finance[OrnsteinUhlenbeckProcess], Finance[PathGenerator], Finance[PathPlot], Finance[SampleValues], Finance[SquareRootDiffusion], Finance[StochasticProcesses], Finance[TimeGrid], Finance[ValueAtRisk], Finance[WienerProcess], RandomTools[MersenneTwister]
|
|
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.
|
|
|