13
$\begingroup$

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]

Here's a image of the simulated results

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, and 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign. $\endgroup$ – bbgodfrey May 21 '15 at 20:21
  • $\begingroup$ Since you "know how to simulate the first part", please include that code (or a simplified version of it) as a starting point to provide context for readers. $\endgroup$ – bbgodfrey May 21 '15 at 20:22
  • $\begingroup$ Sure thing. I used the example in the ItoProcess documentation. The code has been edited into my original question. $\endgroup$ – Shffl May 21 '15 at 20:23
  • $\begingroup$ Done, and thank you to Sjoerd for properly formatting the code. I realized right after adding that it didn't look right, but he beat me to the edit. $\endgroup$ – Shffl May 21 '15 at 20:26
  • $\begingroup$ Is there to be a reversion of parameters if the boundary is re-crossed? In any case, there's no built-in (that I'm aware of) way to "parameterize" the parameters and/or modify them on the fly with some logical construct/test - you'll need to e.g. generate some data, scan it for a crossing, truncate it there, append data with new parameters from that point, rinse-n-repeat... $\endgroup$ – ciao May 21 '15 at 20:51
9
$\begingroup$

Second trial.

The following seems to work. The only restriction so far is that it only works on the first path. I will be looking into that.

ClearAll[x, fun1, fun2, ff, gg]
μ = 1;
σ = 0.3;

fun1[x_, t_] := 
  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}, 1];
ListLinePlot[testdata, PlotRange -> All]

Mathematica graphics

The trick of the baroque Boolean functions is that If returns unevaluated if it cannot determine the truth of its condition (and a third argument is missing). We need this because ItoProcess evaluates its first argument. Another thing that the above makes use of is that False && undefined and True || undefined both evaluate (to False and True, respectively).

$\endgroup$
  • $\begingroup$ Color me surprised if this does what it appears to do, +1 on thought-provoking possibility... $\endgroup$ – ciao May 21 '15 at 21:36
  • $\begingroup$ I have tried a corner case and the start tracker does not appear to do the trick. $\endgroup$ – Shffl May 21 '15 at 23:26
  • $\begingroup$ @Shffl what was the corner case? $\endgroup$ – MarcoB May 21 '15 at 23:48
  • $\begingroup$ I've updated my original question. I suppressed the diffusion component. $\endgroup$ – Shffl May 22 '15 at 0:12
  • $\begingroup$ @Shffl see update $\endgroup$ – Sjoerd C. de Vries May 22 '15 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.