Finance Package Commands For Stochastic Processes
Overview
Basic commands
Ito Processes
See Also
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
restart:withFinance:
For the first example consider the standard Wiener process.
W:=WienerProcess⁡
W:=_W
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
PathPlot⁡S,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
S:=SamplePath⁡Wt,t=0..T,timesteps=100,replications=104
A:=S1..104,50
Statistics:-MeanA
−0.004119959338
Statistics:-StandardDeviationS1..104,50≈T⋅50100;
0.6983974595 ≈ 0.7071067812
Statistics:-StandardDeviationS1..104,75≈T⋅75100;
0.8626421722 ≈ 0.8660254038
You can also simulate any expression involving our stochastic variable.
ExpectedValue⁡expW3,timesteps = 100, replications=104
value=4.321931125,standarderror=0.1820788275
R:=t→ⅇ∫0t0.01⁢W⁡uⅆu:
ExpectedValue⁡R3,timesteps=100,replications=103;
value=1.001642347,standarderror=0.0009304064761
Simple expressions involving multiple stochastic parameters can be handled the same way.
W1 ≔ WienerProcess:
W2≔ WienerProcess:
ExpectedValue⁡max⁡ⅇW1⁡3,ⅇW2⁡3,timesteps=1000,replications=104;
value=8.322545370,standarderror=0.3466860178
ExpectedValue⁡min⁡ⅇW1⁡3,ⅇW2⁡3,timesteps=1000,replications=104;
value=0.9821223967,standarderror=0.02041880265
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.
ExpectedValue⁡PathFunction,W1,0..3,timesteps=100,replications=104
value=4.682401575,standarderror=0.2271049960
Compare this to:
ExpectedValueⅇW1⁡3,timesteps=100,replications=104
value=4.412244372,standarderror=0.1617301713
Consider an example involving two stochastic factors (the same as above).
PathFunction:=A→max⁡ⅇA1,1001,ⅇA2,1001:
ExpectedValue⁡PathFunction,W1,W2,0..3,timesteps=1000,replications=104
value=7.727181378,standarderror=0.2169239333
Here is a procedure that computes the expected value of the absorbing Wiener process.
PathFunction:=procAlocali;forifrom2to11doifAi<=Float⁡0,0thenreturnFloat⁡0,0elifFloat⁡10,−1<=AithenreturnFloat⁡10,−1end ifend do;returnA11end proc:
ExpectedValue⁡PathFunction,W1,0..3,timesteps=10,replications=105
value=0.2356212806,standarderror=0.001339482953
An Ito process is a stochastic process Xt governed by the stochastic differential equation (SDE)
dXt = μXt, t⋅dt+σXt, t⋅dWt,
where μXt, t is the drift parameter and σXt, t is the volatility parameter. The coefficients of the above SDE can be extracted using the Drift and Diffusion commands.
restart; withFinance:
X:=GeometricBrownianMotion⁡100,a,0.5, t:
DriftXt;
a⁢_X⁡t
Diffusion⁡X⁡t;
0.5⁢_X⁡t
Here is a slightly more complicated example.
Y:=BrownianMotion⁡100,a,b, t:
Drift⁡ⅇY⁡t
a⁢ⅇ_X0⁡t+12⁢b2⁢ⅇ_X0⁡t
DiffusionⅇY⁡t
b⁢ⅇ_X0⁡t
Drift⁡ⅇY⁡t2
2⁢a⁢ⅇ_X0⁡t2+2⁢b2⁢ⅇ_X0⁡t2
DriftexpXt⋅Yt
a⁢_X⁡t⁢_X0⁡t⁢ⅇ_X⁡t⁢_X0⁡t+a⁢_X⁡t⁢ⅇ_X⁡t⁢_X0⁡t+0.1250000000⁢_X⁡t2⁢_X0⁡t2⁢ⅇ_X⁡t⁢_X0⁡t+12⁢b2⁢_X⁡t2⁢ⅇ_X⁡t⁢_X0⁡t
Here is an example involving a multi-dimensional process.
Σ ≔ 1.0, 0.5|0.5, 1.0;
W:=WienerProcess⁡Sigma:
DriftexpWt1+Wt2;
2.250000000⁢ⅇ_W⁡t1+_W⁡t2
Here is an Ito process defined explicitly.
X≔ItoProcess1,x⋅t, 0.05⋅x⋅t,x,t
X:=_X1
Drift⁡X⁡t;
t⁢_X1⁡t
0.05⁢t⁢_X1⁡t
A:=SamplePath⁡X⁡t,t=0..3,timesteps=100,replications=10;
PathPlot⁡A,timegrid=0..3,tickmarks=5,5,axes=BOXED,gridlines=true,thickness=2
Term Structures worksheet, Cash Flow Analysis worksheet, Day Counters worksheet, Lattice Methods worksheet, Calendars worksheet
Download Help Document