I want to simulate a geometric Brownian motion and we assume that the volatility of the stock can take just two values $\sigma_1=0.2$ and $\sigma_2=0.8$. We also assume that the jumps up from lower volatility $\sigma_1$ to higher volatility $\sigma_2$ occur as a exponential process with rate $\lambda_1=2$. Likewise, the jumps down from volatility $\sigma_2$ to lower volatility $\sigma_1$ occur as an exponential process with rate $\lambda_2=4$. I know how to simulate a geometric Brownian motion but i can't understand how I simulate the volatility. I must compare a number from the exponential distribution with what on every step to decide if I will make a jump or not?

  • $\begingroup$ I think you need to compare a uniformly distributed random variate $u\sim U(0,1)$ with $z_i \equiv e^{-\lambda_i \Delta t}$, where $\Delta t$ is the time step in your simulation. If $u < z_i$, stay, else go to the other state. $\endgroup$ – Kermittfrog Nov 25 '20 at 8:34
  • $\begingroup$ I tried but doesn't work. $\endgroup$ – Hans Larsen Nov 25 '20 at 10:03
  • $\begingroup$ Well then, why don't you post your code and what you've tried so far in this forum? $\endgroup$ – Kermittfrog Nov 25 '20 at 12:26
  • $\begingroup$ So this is the code. I dont think that the condition in the second if statement is correct. $\endgroup$ – Hans Larsen Nov 25 '20 at 13:39

Besides a couple of ways you might try to improve your code (which I will not do here); your jump check is not working correctly:

In a time step $\Delta t$, the process will jump with probability $\approx exp(-\lambda \Delta t) $. Hence, you need to compare

if (unifrnd(0,1) > exp(-lambda * dt))
  % jump occured
  % flip state
  % no jump occured
  % do not flip state


NB: You might want to simulate a vector of uniforms, and then iterate over elements to get the state $1$ or $2$. From this, you may compose a vector of volatiltities per time step.

I assume you are using Matlab or Octave? If that's the case, vectorisation is king!


Just use the definition of conditional probability. With $\gamma_t \in \{-1,1\}$ an indicator returning 1 if $\sigma = 0.8$ and -1 otherwise, and $x_{1:T}$ the path of the Brownian motion over the time-period $[1,T]$ you have

$$p(x_{1:T}, \gamma_{1:T}) = p(x_{1:T} \vert \gamma_{1:T})p(\gamma_{1:T}).$$

In practice you just simulate, until time $T$, alternating event-times $\tau_i$ from $\text{Exp}(\lambda_1)$ and $\text{Exp}(\lambda_2)$ until $\tau_i > T$. Conditional on these times, you then just simulate your GBM conditional on $\gamma_t$. To make your life easier, choose your step-size such that you get very close to all the event-times $\tau_i$ when simulating the GBM.

  • $\begingroup$ Can you explain it a bit more please? $\endgroup$ – Hans Larsen Nov 26 '20 at 10:32

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.