I would like to simulate an Ito process in which the drift and diffusion terms change after hitting a boundary for the first time.
For example, a Geometric Brownian Motion X which has 0 drift and volatility X dZ_t until X reaches some boundary X-hat. Afterwards, there might be a different drift and volatility.
With my current knowledge of Mathematica, I only know how to simulate the first part, a standard GBM process. What are the next steps?
It is very possible that I'm using poor terminology due to inexperience, and so any comments or pointers are appreciated.
The code I'm using for the standard GBM is the following:
μ = 0;
σ = 0.5;
testfun = ItoProcess[{μ x, σ x}, {x, 1}, {t, 0}];
testdata = RandomFunction[testfun, {0, 1, 0.01}, 5];
ListLinePlot[testdata, AxesLabel -> {t, X[t]},
PlotLabel -> "Simulated Paths", PlotRange -> All]
Update: I have tried the proposed answer and found it does not work, as illustrated by my example below:
μ = 1;
σ = 0;
start = 0;
fun1 := If[x >= 0.5 || start > 0, start++; -x, x];
testfun = ItoProcess[{fun1, σ x}, {x, 0.1}, {t, 0}];
testdata = RandomFunction[testfun, {0, 5, 0.01}, 1];
ListLinePlot[testdata]
This results in a process that "sticks" at the boundary, rather than one that decays afterwards. I believe the problem is that the start
tracker is not working as intended.
Update #2:
I've added a means to simulate multiple paths
ClearAll[x, fun1, fun2, ff, gg]
μ = 1;
σ = 0.3;
fun1[x_, t_] :=
If[t < 0.1, ClearAll[ff, gg]; x,
If[
If[
x < 0.5,
gg = False; If[ff, gg = True]; False,
ff = True
] && ff || gg, -x, x]
]
fun2[x_, t_] :=
If[If[x < 0.5, gg = False; If[ff, gg = True]; False, ff = True] &&
ff || gg, σ x, 0]
testfun = ItoProcess[{fun1[x, t], fun2[x, t]}, {x, 0.1}, {t, 0}];
testdata = RandomFunction[testfun, {0, 5, 0.01}, 5];
ListLinePlot[testdata, PlotRange -> All]