 Stochastic Processes Overview - Maple Help

Home : Support : Online Help : Mathematics : Finance : Stochastic Processes : Stochastic Processes Overview

Finance Package Commands For Stochastic Processes Overview

The Financial Modeling package supports a wide range of stochastic processes used in Financial Engineering. This includes processes for modeling equity prices, mean-reverting processes, pure jump processes, jump diffusions as well as multi-variate Ito processes. In addition, the package provides tools for building more complicated processes from simple ones. Below is the list of supported processes:

 - uni- or multi-variate Brownian motion - constant elasticity of variance (CEV) process - deterministic time-dependent process - a portfolio of stochastic processes that can be dynamically rebalanced - a finite state Markov chain - gamma process - Gaussian process for modeling short-term interest rate introduced by Hull and White - geometric Brownian motion - stochastic volatility process introduced by Heston - general uni- or multi-variate Ito process defined by drift and diffusion - jump-diffusion process introduced by Merton - stochastic process with multiple regimes - Ornstein-Uhlenbeck process - Poisson process including the doubly-stochastic Poisson (Cox) process - square-root diffusion - stochastic volatility with jumps (SVJJ) process - uni- and multi-variate Wiener process including subordinated Wiener process

Here are some related commands.

 - compute a Monte Carlo estimate of the specified expression - compute the drift component of an Ito process - compute the diffusion component of an Ito process - plot sample path(s) of the specified stochastic process - generate a sample path for the specified stochastic process - generate sample values for the specified expression involving stochastic variables - estimate value-at-risk for the specified expression Basic commands

 >

For the first example consider the standard Wiener process.

 > $\mathrm{W}:=\mathrm{WienerProcess}\left(\right)$
 ${W}{:=}{\mathrm{_W}}$ (2.1)

The previous command created a new Maple variable representing the standard Wiener process. This is an ordinary Maple variable with additional attributes containing some information about the underlying stochastic process. This variable is typically accessed in the form $\mathrm{W}\left(\mathrm{t}\right)$, where $\mathrm{t}$ is the time of interest. For example, the following command can be used to generate some replications of the sample path for the underlying stochastic process.

 > $\mathrm{S}:=\mathrm{SamplePath}\left(\mathrm{W}\left(\mathrm{t}\right),\mathrm{t}=0..3,\mathrm{timesteps}=50,\mathrm{replications}=20\right)$
 ${S}{:=}\left[\begin{array}{c}{\mathrm{1..20 x 1..51}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (2.2)
 > You can now generate a larger sample and use tools from the Statistics package to analyze the generated data.

 > $\mathrm{T}:=1.0$
 ${T}{:=}{1.0}$ (2.3)
 > $\mathrm{S}:=\mathrm{SamplePath}\left(\mathrm{W}\left(\mathrm{t}\right),\mathrm{t}=0..\mathrm{T},\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 ${S}{:=}\left[\begin{array}{c}{\mathrm{1..10000 x 1..101}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (2.4)
 > $\mathrm{A}:={\mathrm{S}}_{1..{10}^{4},50}$
 ${A}{:=}\left[\begin{array}{c}{\mathrm{1 .. 10000}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (2.5)
 > $\mathrm{Statistics}:-\mathrm{Mean}\left(\mathrm{A}\right)$
 ${-}{0.004119959338}$ (2.6)
 > $\mathrm{Statistics}:-\mathrm{StandardDeviation}\left({\mathrm{S}}_{1..{10}^{4},50}\right)\approx \sqrt{\mathrm{T}\cdot \frac{50}{100}};$
 $\left({0.6983974595}\right){\approx }\left({0.7071067812}\right)$ (2.7)
 > $\mathrm{Statistics}:-\mathrm{StandardDeviation}\left({\mathrm{S}}_{1..{10}^{4},75}\right)\approx \sqrt{\mathrm{T}\cdot \frac{75}{100}};$
 $\left({0.8626421722}\right){\approx }\left({0.8660254038}\right)$ (2.8)

You can also simulate any expression involving our stochastic variable.

 >
 $\left[{\mathrm{value}}{=}{4.321931125}{,}{\mathrm{standarderror}}{=}{0.1820788275}\right]$ (2.9)
 > $\mathrm{R}:=\mathrm{t}→{ⅇ}^{{∫}_{0}^{\mathrm{t}}0.01\mathrm{W}\left(\mathrm{u}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}ⅆ\mathrm{u}}:$
 > $\mathrm{ExpectedValue}\left(\mathrm{R}\left(3\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{3}\right);$
 $\left[{\mathrm{value}}{=}{1.001642347}{,}{\mathrm{standarderror}}{=}{0.0009304064761}\right]$ (2.10)

Simple expressions involving multiple stochastic parameters can be handled the same way.

 >
 >
 > $\mathrm{ExpectedValue}\left(\mathrm{max}\left({ⅇ}^{{\mathrm{W}}_{1}\left(3\right)},{ⅇ}^{{\mathrm{W}}_{2}\left(3\right)}\right),\mathrm{timesteps}=1000,\mathrm{replications}={10}^{4}\right);$
 $\left[{\mathrm{value}}{=}{8.322545370}{,}{\mathrm{standarderror}}{=}{0.3466860178}\right]$ (2.11)
 > $\mathrm{ExpectedValue}\left(\mathrm{min}\left({ⅇ}^{{\mathrm{W}}_{1}\left(3\right)},{ⅇ}^{{\mathrm{W}}_{2}\left(3\right)}\right),\mathrm{timesteps}=1000,\mathrm{replications}={10}^{4}\right);$
 $\left[{\mathrm{value}}{=}{0.9821223967}{,}{\mathrm{standarderror}}{=}{0.02041880265}\right]$ (2.12)

Alternatively, you can implement any kind of path function using Maple procedures. This function will be called on every replication of the sample path. In the case of a single stochastic factor the path function will be passed a one-dimensional array containing the sample path. In the case of multiple stochastic factors, the path function will be passed a two-dimensional array where each row contains a sample path for the corresponding stochastic factor.

Consider, for example, a path function that returns ${\mathrm{W}}_{1}\left(3\right).$ In the case when the path function is given explicitly, you must know the number of time steps in advance. You will use $100$ time steps in this example, which means that the sample path will contain $101$ points.

 > $\mathrm{PathFunction}:=\mathrm{A}→{ⅇ}^{{\mathrm{A}}_{101}}:$

Now you can compute the expected value of this path function.

 > $\mathrm{ExpectedValue}\left(\mathrm{PathFunction},{\mathrm{W}}_{1},0..3,\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 $\left[{\mathrm{value}}{=}{4.682401575}{,}{\mathrm{standarderror}}{=}{0.2271049960}\right]$ (2.13)

Compare this to:

 > $\mathrm{ExpectedValue}\left({ⅇ}^{{\mathrm{W}}_{1}\left(3\right)},\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 $\left[{\mathrm{value}}{=}{4.412244372}{,}{\mathrm{standarderror}}{=}{0.1617301713}\right]$ (2.14)

Consider an example involving two stochastic factors (the same as above).

 > $\mathrm{PathFunction}:=\mathrm{A}→\mathrm{max}\left({ⅇ}^{{\mathrm{A}}_{1,1001}},{ⅇ}^{{\mathrm{A}}_{2,1001}}\right):$
 > $\mathrm{ExpectedValue}\left(\mathrm{PathFunction},⟨{\mathrm{W}}_{1},{\mathrm{W}}_{2}⟩,0..3,\mathrm{timesteps}=1000,\mathrm{replications}={10}^{4}\right)$
 $\left[{\mathrm{value}}{=}{7.727181378}{,}{\mathrm{standarderror}}{=}{0.2169239333}\right]$ (2.15)

Here is a procedure that computes the expected value of the absorbing Wiener process.

 > $\mathrm{PathFunction}:=proc\left(\mathrm{A}\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}local\mathrm{i};\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}for\mathrm{i}from2to11do\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}if\mathrm{A}\left[\mathrm{i}\right]<=\mathrm{Float}\left(0,0\right)then\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}return\mathrm{Float}\left(0,0\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}elif\mathrm{Float}\left(10,−1\right)<=\mathrm{A}\left[\mathrm{i}\right]then\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}return\mathrm{Float}\left(10,−1\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}end if\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}end do;\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}return\mathrm{A}\left[11\right]\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}end proc:$
 > $\mathrm{ExpectedValue}\left(\mathrm{PathFunction},{\mathrm{W}}_{1},0..3,\mathrm{timesteps}=10,\mathrm{replications}={10}^{5}\right)$
 $\left[{\mathrm{value}}{=}{0.2356212806}{,}{\mathrm{standarderror}}{=}{0.001339482953}\right]$ (2.16) Ito Processes

An Ito process is a stochastic process $\mathrm{X}\left(\mathrm{t}\right)$ governed by the stochastic differential equation (SDE)

where  is the drift parameter and  is the volatility parameter. The coefficients of the above SDE can be extracted using the Drift and Diffusion commands.

 >
 >
 > $\mathrm{Drift}\left(\mathrm{X}\left(\mathrm{t}\right)\right);$
 ${a}{}{\mathrm{_X}}{}\left({t}\right)$ (3.1)
 > $\mathrm{Diffusion}\left(\mathrm{X}\left(\mathrm{t}\right)\right);$
 ${0.5}{}{\mathrm{_X}}{}\left({t}\right)$ (3.2)

Here is a slightly more complicated example.

 >
 > $\mathrm{Drift}\left({ⅇ}^{\mathrm{Y}\left(\mathrm{t}\right)}\right)$
 ${a}{}{{ⅇ}}^{{\mathrm{_X0}}{}\left({t}\right)}{+}\frac{{1}}{{2}}{}{{b}}^{{2}}{}{{ⅇ}}^{{\mathrm{_X0}}{}\left({t}\right)}$ (3.3)
 > $\mathrm{Diffusion}\left({ⅇ}^{\mathrm{Y}\left(\mathrm{t}\right)}\right)$
 ${b}{}{{ⅇ}}^{{\mathrm{_X0}}{}\left({t}\right)}$ (3.4)
 > $\mathrm{Drift}\left({\left({ⅇ}^{\mathrm{Y}\left(\mathrm{t}\right)}\right)}^{2}\right)$
 ${2}{}{a}{}{\left({{ⅇ}}^{{\mathrm{_X0}}{}\left({t}\right)}\right)}^{{2}}{+}{2}{}{{b}}^{{2}}{}{\left({{ⅇ}}^{{\mathrm{_X0}}{}\left({t}\right)}\right)}^{{2}}$ (3.5)
 > $\mathrm{Drift}\left(\mathrm{exp}\left(\mathrm{X}\left(\mathrm{t}\right)\cdot \mathrm{Y}\left(\mathrm{t}\right)\right)\right)$
 ${a}{}{\mathrm{_X}}{}\left({t}\right){}{\mathrm{_X0}}{}\left({t}\right){}{{ⅇ}}^{{\mathrm{_X}}{}\left({t}\right){}{\mathrm{_X0}}{}\left({t}\right)}{+}{a}{}{\mathrm{_X}}{}\left({t}\right){}{{ⅇ}}^{{\mathrm{_X}}{}\left({t}\right){}{\mathrm{_X0}}{}\left({t}\right)}{+}{0.1250000000}{}{{\mathrm{_X}}{}\left({t}\right)}^{{2}}{}{{\mathrm{_X0}}{}\left({t}\right)}^{{2}}{}{{ⅇ}}^{{\mathrm{_X}}{}\left({t}\right){}{\mathrm{_X0}}{}\left({t}\right)}{+}\frac{{1}}{{2}}{}{{b}}^{{2}}{}{{\mathrm{_X}}{}\left({t}\right)}^{{2}}{}{{ⅇ}}^{{\mathrm{_X}}{}\left({t}\right){}{\mathrm{_X0}}{}\left({t}\right)}$ (3.6)

Here is an example involving a multi-dimensional process.

 >
 ${\mathrm{Σ}}{:=}\left[\begin{array}{cc}{1.0}& {0.5}\\ {0.5}& {1.0}\end{array}\right]$ (3.7)
 > $\mathrm{W}:=\mathrm{WienerProcess}\left(\mathrm{Sigma}\right):$
 > $\mathrm{Drift}\left(\mathrm{exp}\left(\mathrm{W}\left(\mathrm{t}\right)\left[1\right]+\mathrm{W}\left(\mathrm{t}\right)\left[2\right]\right)\right);$
 ${2.250000000}{}{{ⅇ}}^{{{\mathrm{_W}}{}\left({t}\right)}_{{1}}{+}{{\mathrm{_W}}{}\left({t}\right)}_{{2}}}$ (3.8)

Here is an Ito process defined explicitly.

 >
 ${X}{:=}{\mathrm{_X1}}$ (3.9)
 > $\mathrm{Drift}\left(\mathrm{X}\left(\mathrm{t}\right)\right);$
 ${t}{}{\mathrm{_X1}}{}\left({t}\right)$ (3.10)
 > $\mathrm{Diffusion}\left(\mathrm{X}\left(\mathrm{t}\right)\right);$
 ${0.05}{}{t}{}{\mathrm{_X1}}{}\left({t}\right)$ (3.11)
 > $\mathrm{A}:=\mathrm{SamplePath}\left(\mathrm{X}\left(\mathrm{t}\right),\mathrm{t}=0..3,\mathrm{timesteps}=100,\mathrm{replications}=10\right);$
 ${A}{:=}\left[\begin{array}{c}{\mathrm{1..10 x 1..101}}{\mathrm{Array}}\\ {\mathrm{Data Type:}}{{\mathrm{float}}}_{{8}}\\ {\mathrm{Storage:}}{\mathrm{rectangular}}\\ {\mathrm{Order:}}{\mathrm{C_order}}\end{array}\right]$ (3.12)
 > $\mathrm{PathPlot}\left(\mathrm{A},\mathrm{timegrid}=0..3,\mathrm{tickmarks}=\left(\left[5,5\right]\right),\mathrm{axes}=\mathrm{BOXED},\mathrm{gridlines}=\mathrm{true},\mathrm{thickness}=2\right)$  See Also