Stochastic Processes Overview - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


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

Finance Package Commands For Stochastic Processes

 

Overview

Basic commands

Ito Processes

See Also

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:

 

BrownianMotion

-

uni- or multi-variate Brownian motion

CEVProcess

-

constant elasticity of variance (CEV) process

DeterministicProcess

-

deterministic time-dependent process

DynamicPortfolio

-

a portfolio of stochastic processes that can be dynamically rebalanced

MarkovChain

-

a finite state Markov chain

GammaProcess

-

gamma process

GaussMarkovProcess

-

Gaussian process for modeling short-term interest rate introduced by Hull and White

GeometricBrownianMotion

-

geometric Brownian motion

HestonProcess

-

stochastic volatility process introduced by Heston

ItoDiffusion

-

general uni- or multi-variate Ito process defined by drift and diffusion

MertonJumpDiffusion

-

jump-diffusion process introduced by Merton

RegimeSwitchingProcess

-

stochastic process with multiple regimes

OrnsteinUhlenbeckProcess

-

Ornstein-Uhlenbeck process

PoissonProcess

-

Poisson process including the doubly-stochastic Poisson (Cox) process

SquareRootDiffusion

-

square-root diffusion

SVJJProcess

-

stochastic volatility with jumps (SVJJ) process

WienerProcess

-

uni- and multi-variate Wiener process including subordinated Wiener process

 

Here are some related commands.

 

ExpectedValue

-

compute a Monte Carlo estimate of the specified expression

Drift

-

compute the drift component of an Ito process

Diffusion

-

compute the diffusion component of an Ito process

PathPlot

-

plot sample path(s) of the specified stochastic process

SamplePath

-

generate a sample path for the specified stochastic process

SampleValues

-

generate sample values for the specified expression involving stochastic variables

ValueAtRisk

-

estimate value-at-risk for the specified expression

Basic commands

restart:withFinance: 

 

For the first example consider the standard Wiener process.

 

W:=WienerProcess

W:=_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 Wt, where 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.

 

S:=SamplePathWt,t=0..3,timesteps=50,replications=20

PathPlotS,timegrid = 0..3,color = red..blue, thickness=3, axes = BOXED, tickmarks = 10, 10, gridlines

You can now generate a larger sample and use tools from the Statistics package to analyze the generated data.

 

T:=1.0

T:=1.0

(2.2)

S:=SamplePathWt,t=0..T,timesteps=100,replications=104

A:=S1..104,50

Statistics:-MeanA

0.004119959338

(2.3)

Statistics:-StandardDeviationS1..104,50T50100;

0.69839745950.7071067812

(2.4)

Statistics:-StandardDeviationS1..104,75T75100;

0.86264217220.8660254038

(2.5)

 

You can also simulate any expression involving our stochastic variable.

 

ExpectedValueexpW3,timesteps = 100, replications=104

value=4.321931125,standarderror=0.1820788275

(2.6)

R:=t→ⅇ∫0t0.01Wuⅆu:

ExpectedValueR3,timesteps=100,replications=103;

value=1.001642347,standarderror=0.0009304064761

(2.7)

 

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

 

W1  WienerProcess:

W2 WienerProcess:

ExpectedValuemaxⅇW13,ⅇW23,timesteps=1000,replications=104;

value=8.322545370,standarderror=0.3466860178

(2.8)

ExpectedValueminⅇW13,ⅇW23,timesteps=1000,replications=104;

value=0.9821223967,standarderror=0.02041880265

(2.9)

 

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

 

PathFunction:=A→ⅇA101:

 

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

 

ExpectedValuePathFunction,W1,0..3,timesteps=100,replications=104

value=4.682401575,standarderror=0.2271049960

(2.10)

 

Compare this to:

 

ExpectedValueⅇW13,timesteps=100,replications=104

value=4.412244372,standarderror=0.1617301713

(2.11)

 

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

 

PathFunction:=A→maxⅇA1,1001,ⅇA2,1001:

ExpectedValuePathFunction,W1,W2,0..3,timesteps=1000,replications=104

value=7.727181378,standarderror=0.2169239333

(2.12)

 

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

PathFunction:=procAlocali&semi;forifrom2to11doifAi<=Float0&comma;0thenreturnFloat0&comma;0elifFloat10&comma;&minus;1<=AithenreturnFloat10&comma;&minus;1end ifend do&semi;returnA11end proc&colon;

ExpectedValuePathFunction&comma;W1&comma;0..3&comma;timesteps&equals;10&comma;replications&equals;105

value&equals;0.2356212806&comma;standarderror&equals;0.001339482953

(2.13)

Ito Processes

An Ito process is a stochastic process Xt governed by the stochastic differential equation (SDE)

 

dXt &equals; &mu;Xt&comma; tdt&plus;&sigma;Xt&comma; tdWt&comma;

 

where &mu;Xt&comma; t is the drift parameter and &sigma;Xt&comma; t is the volatility parameter. The coefficients of the above SDE can be extracted using the Drift and Diffusion commands.

 

restart&semi; withFinance&colon;

X:=GeometricBrownianMotion100&comma;a&comma;0.5&comma; t&colon;

DriftXt&semi;

a_Xt

(3.1)

DiffusionXt&semi;

0.5_Xt

(3.2)

Here is a slightly more complicated example.

 

Y:=BrownianMotion100&comma;a&comma;b&comma; t&colon;

Drift&ExponentialE;Yt

a&ExponentialE;_X0t&plus;12b2&ExponentialE;_X0t

(3.3)

Diffusion&ExponentialE;Yt

b&ExponentialE;_X0t

(3.4)

Drift&ExponentialE;Yt2

2a&ExponentialE;_X0t2&plus;2b2&ExponentialE;_X0t2

(3.5)

DriftexpXtYt

a_Xt_X0t&ExponentialE;_Xt_X0t&plus;a_Xt&ExponentialE;_Xt_X0t&plus;0.1250000000_Xt2_X0t2&ExponentialE;_Xt_X0t&plus;12b2_Xt2&ExponentialE;_Xt_X0t

(3.6)

Here is an example involving a multi-dimensional process.

 

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

W:=WienerProcessSigma&colon;

DriftexpWt1&plus;Wt2&semi;

2.250000000&ExponentialE;_Wt1&plus;_Wt2

(3.7)

Here is an Ito process defined explicitly.

 

XItoProcess1&comma;xt&comma; 0.05xt&comma;x&comma;t

X:=_X1

(3.8)

DriftXt&semi;

t_X1t

(3.9)

DiffusionXt&semi;

0.05t_X1t

(3.10)

A:=SamplePathXt&comma;t&equals;0..3&comma;timesteps&equals;100&comma;replications&equals;10&semi;

PathPlotA&comma;timegrid&equals;0..3&comma;tickmarks&equals;5&comma;5&comma;axes&equals;BOXED&comma;gridlines&equals;true&comma;thickness&equals;2

See Also

Term Structures worksheet, Cash Flow Analysis worksheet, Day Counters worksheet, Lattice Methods worksheet, Calendars worksheet