Finance - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Finance : Stochastic Processes : Finance/SamplePath

Finance

  

SamplePath

  

generate sample path(s) for a stochastic process

 

Calling Sequence

Parameters

Options

Description

Examples

References

Compatibility

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 m×n, where m is the requested number of replications of the sample path (see the replications option) and n 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 m×d×n, where m and n are the same as in the one-dimensional case, and d 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 T0..T1, where T0 and T1 are non-negative constants such that T0<T1.

  

Note that if 0<T0, the value at T0 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 T0 and T1, but will have no effect on the value at T0. To reduce the bias, use a time interval of the form 0..T1. All stochastic variables involved in expression should be of the form Xt. If X is multi-dimensional stochastic, then the individual components of X can be accessed using the notation Xti.

• 

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 A. If pathgenerator is one-dimensional, A is a one-dimensional array of size n. If pathgenerator is multi-dimensional, A is a two-dimensional array of size k×n, where k is the dimension of pathgenerator. Then SamplePath evaluates fB&comma;A, where B is a preallocated one-dimensional floating-point array of the same size as A. The values stored in B 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, A is now of size d×n. Note the difference between the SamplePath(transform, pathgenerator, opts) and SamplePath(1, transform, pathgenerator, opts) calling sequences. The first returns an array of size m×n, while the other returns an array of size m×1×n.

• 

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

withFinance&colon;

XWienerProcess&colon;

WWienerProcess1.0&comma;0.5&verbar;0.5&comma;1.0&colon;

Create 20 replications of the sample path of X on the interval 0..1 using 100 time steps.

ASamplePathXt&comma;t&equals;0..1&comma;timesteps&equals;100&comma;replications&equals;20

A:= 1..20 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(1)

Here is a single realization of the sample path.

A1

1 .. 101 ArrayData Type: float8Storage: rectangularOrder: C_order

(2)

Here is an example involving a two-dimensional process.

BSamplePathWt1&plus;Wt2&comma;t&equals;0..1&comma;timesteps&equals;100&comma;replications&equals;20

B:= 1..20 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(3)

B1

1 .. 101 ArrayData Type: float8Storage: rectangularOrder: C_order

(4)

Create path generators for X and W on the interval 0..5 and use them to generate sample paths for X and W.

PPathGeneratorX&comma;TimeGrid5&comma;100&colon;

ASamplePathP&comma;replications&equals;20

A:= 1..20 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(5)

MPathGeneratorW&comma;TimeGrid5&comma;100&colon;

BSamplePathM&comma;replications&equals;20

B:= 1..20 x 1..2 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(6)

Here are realizations of the sample paths.

A1

1 .. 101 ArrayData Type: float8Storage: rectangularOrder: C_order

(7)

B1

1..2 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(8)

Use the above path generator to generate sample paths for the process &ExponentialE;At.

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;

f:=procB&comma;Alocald&comma;i&semi;d:=rtable_dimsA&semi;forifromlhsdtorhsddoB&lsqb;i&rsqb;:=expA&lsqb;i&rsqb;end doend proc

(9)

SamplePathf&comma;P&comma;replications&equals;20

1..20 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(10)

Simulate the one-dimensional process Wt1&plus;Wt2 where W 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:

SamplePathf2&comma;M&comma;replications&equals;20

1..20 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(11)

This is the same example using the last calling sequence. Note the difference between procedures f2 and F2.

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:

SamplePath1&comma;F2&comma;M&comma;replications&equals;20

1..20 x 1..1 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(12)

Simulate the three-dimensional process Wt1&comma;Wt2&comma;Wt1&plus;Wt2 where W 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:

SamplePath3&comma;F&comma;M&comma;replications&equals;20

1..20 x 1..3 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(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.

SRandomTools:-GetState&colon;

Use the same state of the random number generator to compare the results.

RandomTools:-SetStatestate&equals;S&colon;

A1SamplePathXt2&comma;t&equals;0..10&comma;timesteps&equals;10

A1:= 1..1 x 1..11 ArrayData Type: float8Storage: rectangularOrder: C_order

(14)

This is the same example as above but using a Maple procedure.

RandomTools:-SetStatestate&equals;S&colon;

f := proc(B, A) local i; for i from 1 to 11 do B[i] := A[i]^2; end do; end proc:

A2SamplePathf&comma;X&comma;0..10&comma;timesteps&equals;10

A2:= 1..1 x 1..11 ArrayData Type: float8Storage: rectangularOrder: C_order

(15)

This is the same example using an explicitly defined time grid.

TTimeGrid0&comma;1&comma;2&comma;3&comma;4&comma;5&comma;6&comma;7&comma;8&comma;9&comma;10

T:=moduleend module

(16)

This is a multi-dimensional path that depends on one stochastic factor.

SamplePathXt&comma;Xt&comma;t&equals;0..10&comma;timesteps&equals;10

1..1 x 1..2 x 1..11 ArrayData Type: float8Storage: rectangularOrder: C_order

(17)

This is a multivariate stochastic process.

&Sigma;1.0&comma;0.5&verbar;0.5&comma;1.0

&Sigma;:=1.00.50.51.0

(18)

WWienerProcess&Sigma;

W:=_W1

(19)

SamplePathWt&comma;t&equals;0..3&comma;timesteps&equals;10&comma;replications&equals;104

1..10000 x 1..2 x 1..11 ArrayData Type: float8Storage: rectangularOrder: C_order

(20)

SSamplePathWt1&comma;Wt2&comma;Wt1&plus;Wt2&comma;t&equals;0..3&comma;timesteps&equals;9&comma;replications&equals;104

S:= 1..10000 x 1..3 x 1..10 ArrayData Type: float8Storage: rectangularOrder: C_order

(21)

Here is the first replication of the sample path.

mapevalf5&comma;S1

0.0.317170.164901.19061.46471.56991.64501.93991.52511.33820.0.0604330.355771.06830.694080.121850.221090.985851.20041.18800.0.377600.520672.25892.15871.69181.86612.92582.72552.5262

(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.

JPoissonProcess0.3

J:=_P

(23)

SSamplePath5Jtt&plus;Wt1&comma;t&equals;0..3&comma;timesteps&equals;100&comma;replications&equals;10

S:= 1..10 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(24)

PathPlotS&comma;timegrid&equals;0..3&comma;color&equals;red..blue&comma;thickness&equals;3

Here are some expressions involving stochastic variables.

YWienerProcess

Y:=_W2

(25)

Zt&rarr;&ExponentialE;0.05t&plus;0.3Yt

Z:=t&rarr;&ExponentialE;0.05t&plus;0.3Yt

(26)

Ut&rarr;maximizeZu&comma;u&equals;0..t

U:=t&rarr;maximizeZu&comma;u&equals;0..t

(27)

SSamplePathZt&comma;Ut&comma;t&equals;0..3&comma;timesteps&equals;100&comma;replications&equals;5

S:= 1..5 x 1..2 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(28)

Vt&rarr;1&int;0tZu&DifferentialD;ut

V:=t&rarr;&int;0tZu&DifferentialD;ut

(29)

SSamplePathZt&comma;Vt&comma;t&equals;0..3&comma;timesteps&equals;100&comma;replications&equals;5

S:= 1..5 x 1..2 x 1..101 ArrayData Type: float8Storage: rectangularOrder: C_order

(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`

SSamplePathtestproc&comma;Y&comma;0..3&comma;timesteps&equals;10&comma;replications&equals;10

S:= 1..10 x 1..11 ArrayData Type: float8Storage: rectangularOrder: C_order

(31)

PathPlotS&comma;timegrid&equals;0..3&comma;thickness&equals;3&comma;color&equals;red..blue

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.

• 

For more information on Maple 15 changes, see Updates in Maple 15.

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]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam