SampleValues - Maple Help

Finance

 SampleValues
 generate sample value(s) for the specified expression

 Calling Sequence SampleValues(pathfunction, pathgenerator, opts) SampleValues(pathfunction, process, timegrid, opts) SampleValues(pathfunction, process, timeinterval, opts) SampleValues(expression, opts)

Parameters

 pathfunction - procedure; path function pathgenerator - path generator data structure; path generator process - one- or multi-dimensional stochastic process, or list or vector of one-dimensional stochastic processes timegrid - range or time grid data structure; time grid timeinterval - range; time interval expression - algebraic expression; expression whose value is to be generated opts - (optional) equation(s) of the form option = value where option is one of replications or timesteps; specify options for the SampleValues 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 an explicit time grid is specified. By default, only one time step is used.

Description

 • The SampleValues(pathfunction, pathgenerator, opts) calling sequence computes a Monte Carlo estimate of pathfunction using sample paths generated by pathgenerator. The procedure consists of the following steps:
 – Generate a replication of the sample path using the specified path generator and store these values as a Maple Array, for example $A$. In the case of a one-dimensional process $A$ is a one-dimensional array of size $n$, where $n$ is the number of points in the time grid (the number of time steps plus one). In the case of a multi-dimensional process, $A$ is a two-dimensional array of size $\left[m,n\right]$, where $m$ is the dimension of the underlying stochastic process and $n$ is the same as in the one-dimensional case.
 – Compute the value $\mathrm{pathfunction}\left(A\right)$.
 – Repeat the above two steps the specified number of times (see the replications option).
 • The SampleValues(pathfunction, process, timegrid, opts) and SampleValues(pathfunction, process, timeinterval, opts) calling sequences first construct the corresponding path generator and then perform the same computations as above.
 • The parameter timeinterval must be of type range ${T}_{0}..{T}_{1}$, where ${T}_{0}$ and ${T}_{1}$ are non-negative constants such that ${T}_{0}<{T}_{1}$.
 • When the ExpectedValue(pathfunction, process, timeinterval, opts) calling sequence is used, the uniform time grid between ${T}_{0}$ and ${T}_{1}$ (with time steps $\mathrm{dt}=\frac{{T}_{1}-{T}_{0}}{\mathrm{timesteps}}$) is generated.
 Note that if $0<{T}_{0}$, the value at ${T}_{0}$ 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 ${T}_{0}$ and ${T}_{1}$, but will have no effect on the value at ${T}_{0}$. To reduce the bias, use a time interval of the form $0..{T}_{1}$.
 • The SampleValues(expression, opts) calling sequence attempts to extract all the stochastic variables involved in expression and generate the corresponding path generator and path function using the specified number of time steps. In particular, SampleValues will extract all time instances involved in expression and adjust them so that they belong to the grid.
 All stochastic variables involved in expression should be of the form $X\left(t\right)$, where $t$ is some expression. If $X$ is multi-dimensional stochastic, then the individual components of $X$ can be accessed using the notation ${X\left(t\right)}_{i}$.

Examples

 > $\mathrm{with}\left(\mathrm{Finance}\right):$

Here is a simple one-dimensional stochastic process.

 > $X≔\mathrm{WienerProcess}\left(\right)$
 ${X}{≔}{\mathrm{_W}}$ (1)
 > $S≔\mathrm{SampleValues}\left(\mathrm{exp}\left(X\left(3\right)\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 > $\mathrm{Statistics}:-\mathrm{DataSummary}\left(S,\mathrm{output}=\left[\mathrm{mean},\mathrm{standarddeviation}\right]\right)$
 $\left[{4.41583032222043}{,}{14.7026267487629}\right]$ (2)

Use a Maple procedure to compute the same expression.

 > $T≔\mathrm{TimeGrid}\left(3,100\right):$
 > $\mathrm{GX}≔\mathrm{PathGenerator}\left(X,T\right):$
 > $S≔\mathrm{SampleValues}\left(A↦\mathrm{exp}\left(A\left[101\right]\right),\mathrm{GX},\mathrm{replications}={10}^{4}\right)$
 > $\mathrm{Statistics}:-\mathrm{DataSummary}\left(S,\mathrm{output}=\left[\mathrm{mean},\mathrm{standarddeviation}\right]\right)$
 $\left[{4.33299075633332}{,}{18.2389408161531}\right]$ (3)

Here is an example involving a multivariate stochastic process.

 > $\mathrm{\Sigma }≔⟨⟨1.0,0.5⟩|⟨0.5,1.0⟩⟩$
 ${\mathrm{\Sigma }}{≔}\left[\begin{array}{cc}{1.0}& {0.5}\\ {0.5}& {1.0}\end{array}\right]$ (4)
 > $W≔\mathrm{WienerProcess}\left(\mathrm{\Sigma }\right)$
 ${W}{≔}{\mathrm{_W0}}$ (5)
 > $S≔\mathrm{SampleValues}\left(\mathrm{max}\left(W\left(3\right)\left[1\right],W\left(3\right)\left[1\right]\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 > $\mathrm{Statistics}:-\mathrm{DataSummary}\left(S,\mathrm{output}=\left[\mathrm{mean},\mathrm{standarddeviation}\right]\right)$
 $\left[{0.0106647008230180}{,}{1.72908152039724}\right]$ (6)

Here is the same computation using Maple procedures.

 > $T≔\mathrm{TimeGrid}\left(3,100\right):$
 > $\mathrm{GW}≔\mathrm{PathGenerator}\left(W,T\right):$
 > $S≔\mathrm{SampleValues}\left(A↦\mathrm{max}\left(A\left[1\right]\left[101\right],A\left[2\right]\left[101\right]\right),\mathrm{GW},\mathrm{replications}={10}^{5}\right)$
 > $\mathrm{Statistics}:-\mathrm{DataSummary}\left(S,\mathrm{output}=\left[\mathrm{mean},\mathrm{kurtosis},\mathrm{standarddeviation}\right]\right)$
 $\left[{0.698559577951287}{,}{3.01709634240065}{,}{1.58748095181072}\right]$ (7)

Use a two-dimensional Ito process using two one-dimensional projections and a given covariance matrix.

 > $X≔\mathrm{GeometricBrownianMotion}\left(100.0,0.05,0.3,t\right)$
 ${X}{≔}{\mathrm{_X2}}$ (8)
 > $Y≔\mathrm{GeometricBrownianMotion}\left(100.0,0.07,0.2,t\right)$
 ${Y}{≔}{\mathrm{_X3}}$ (9)
 > $\mathrm{\Sigma }≔⟨⟨1|0.5⟩,⟨0.5|1⟩⟩$
 ${\mathrm{\Sigma }}{≔}\left[\begin{array}{cc}{1}& {0.5}\\ {0.5}& {1}\end{array}\right]$ (10)
 > $Z≔\mathrm{ItoProcess}\left(⟨X,Y⟩,\mathrm{\Sigma }\right)$
 ${Z}{≔}{\mathrm{_X4}}$ (11)
 > $\mathrm{Drift}\left(Z\left(t\right)\right)$
 $\left[\begin{array}{c}{0.05}{}{{\mathrm{_X4}}{}\left({t}\right)}_{{1}}\\ {0.07}{}{{\mathrm{_X4}}{}\left({t}\right)}_{{2}}\end{array}\right]$ (12)
 > $\mathrm{Diffusion}\left(Z\left(t\right)\right)$
 $\left[\begin{array}{cc}{0.3}{}{{\mathrm{_X4}}{}\left({t}\right)}_{{1}}& {0.15}{}{{\mathrm{_X4}}{}\left({t}\right)}_{{1}}\\ {0.10}{}{{\mathrm{_X4}}{}\left({t}\right)}_{{2}}& {0.2}{}{{\mathrm{_X4}}{}\left({t}\right)}_{{2}}\end{array}\right]$ (13)
 > $\mathrm{SampleValues}\left(\mathrm{max}\left(X\left(1\right)-Y\left(1\right),0\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 > $\mathrm{SampleValues}\left(\mathrm{max}\left(Z\left(1\right)\left[1\right]-Z\left(1\right)\left[2\right],0\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$

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[SampleValues] command was introduced in Maple 15.