Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to run Geometric Brownian Motion process in STATA?

    Hey, everyone!

    I am learning theoretical knowledge of GBM process at the moment and wonder that, is everyone familiar with using STATA to run GBM process?

    Many thanks for your help!

  • #2
    Jae Li --

    I'm not sure if this is exactly what you want, but I think you can generate a Brownian motion using something like the following. The idea is to just apply the usual Euler approximation scheme:

    yt+d = yt + m*d + s*dW

    where m is the drift parameter, s is the deviation parameter, and dW is the normal(0,d) Brownian motion. Here is my code:

    Code:
    clear all
    set obs 10000
    
    scalar mu = .0001
    scalar sigma = .4
    scalar Delta = .1
    
    /* scheme is y[t+1] = y[t] + mu*delta + sigma*dW */
    
    gen dW = rnormal(0,Delta)
    
    gen t = _n
    tsset t
    
    gen y = .
    replace y = mu*Delta + sigma*dW in 1
    replace y = l.y +mu*Delta + sigma*dW if y == . 
    
    tsline y
    The key to sequentially replacing things is the

    Code:
    y = l.y + something if y == .
    block, credit for which I think should go to Nick Cox .

    Hope that helps!

    Matthew J. Baker

    Comment


    • #3
      Hi @Matthew J. Baker

      Thank you for the swift reply with providing the codes!

      May I ask that why do you use the approximate numerical solution (i.e., Euler method) instead of the exact solution (i.e. GBM) to simluate the whole trajectory? As the GBM is the continuously closed-form solution of the SDEs. If I want to simulate the GBM by using Monte Carlo simulations, can I directly do that without converting it to the discrete form (i.e., Euler method)?

      Thank you for your time and help! I will highly look forward to hearing from you soon!

      Best regards,

      Jae

      Comment


      • #4
        Jae Li --

        If I'm understanding your response correctly, what you would like to do is just use the basic "independent increments" property of Brownian motion and rely on the actual conditional distribution to simulate the Brownian motion. That is, for a standard brownian motion, one has:

        Y[t+1]-Y[t] ~ N(mt, s^2t)

        which implies:

        Y[t+1] ~ N(Y[t]+mt,s^2t)

        Then, if we just let the length of a time period be one, we simply have:


        Y[t+1] ~ N(Y[t]+m,s^2)

        Here is the code:

        Code:
        clear
        set obs 10000
        
        gen y = .
        replace y = .
        scalar mu = .01
        scalar s  = .4
        
        gen t = _n
        tsset t
        
        replace y = 0 in 1
        
        replace y = rnormal(l.y+mu,s) if y == .
        
        tsline y
        If one was interested in a Geometric Brownian Motion, I don't think things are all that different, but one instead works with exponentiation of variables. Does that help?

        Best,

        Matthew J. Baker

        Comment


        • #5
          @Matthew J. Baker thanks a lot!!!

          Comment

          Working...
          X