Simulating stock prices using GBM

Discussion in 'App Development' started by earth_imperator, Jul 27, 2023.

  1. @ph1l, for geometric_brownian_motion(.). do you happen to know what the param T expects?
    Let's say I need to generate monthly prices for 1 year, ie. 12 per year, then I guess N has to be 12. But what value to pass for T ? Is it 1.0 ?
    Is there any test code by the author that demonstrates the usage of these functions?

    Update: OK, figured it out: yes T is time in years, ie. in my case 1.0
     
    Last edited: Jul 29, 2023
    #21     Jul 29, 2023
  2. @ph1l, this is one of the best GBM algorithms I have tested so far, but IMO still not a correct GBM.
    Btw, there is a bug in the description in both (or all three) functions: param T is (or has to be) of type float, not int.
    Another shortcoming in the algorithm is that it always generates the given initial price, G0, as the first output. This is unnecessary und better should be removed, IMO.
    And a tip for programmers: this code uses (implicitly) vector programming... :), to speed it up, so it's not that easy to grasp the algorithm... :) Ie. it works by operating on vectors... A drawback of this approach is that the vectors can get really big, depending on N, and so the memory use.

    And: I myself don't have the correct GBM algorithm yet; I just know it can't be correct b/c it does not pass some stochastic tests...
     
    Last edited: Jul 30, 2023
    #22     Jul 30, 2023
  3. I'm still seeking a good GBM algorithm.

    To all: any other good GBM algorithm you can recommend?
     
    #23     Aug 4, 2023
  4. Proof that GBM is wrong

    GBM and lognormal with same parameters will be compared to each other.

    1) lognormal ( https://en.wikipedia.org/wiki/Log-normal_distribution#Generation_and_parameters ) :
    Code:
      St = S0 * exp(u     + s *           rndSND)      # for t=1
      St = S0 * exp(u * t + s * sqrt(t) * rndSND)      # for any t
    
      where rndSND is a random number from the standard normal distribution (ie. u=0 and s=1)
      In this case it can be seen as the "z" value, here using -1 and +1 for -1SD and +1SD
    
      Example: see #3 below
    
    2) GBM ( https://en.wikipedia.org/wiki/Geometric_Brownian_motion#Solving_the_SDE ) :
    Code:
      St = S0 * exp((u - s * s / 2) * t + s * Wt)
    
      where Wt = sqrt(t) * rndSND, and
      where rndSND is a random number from the standard normal distribution (ie. u=0 and s=1)
      In this case it can be seen as the "z" value, here using -1 and +1 for -1SD and +1SD
    
      Example: see #3 below
    
    3) Proof that GBM is wrong: below rndSND can be seen as the "z" value, here -1 and +1 for -1SD and +1SD :
    Code:
    "-1SD" :
    S0=100 ; u=0.0; s=0.3 ; t=1 ; rndSND=-1.0 ; S0 * exp(u * t + s * sqrt(t) * rndSND) ; Wt = sqrt(t) * rndSND; S0 * exp((u - s * s / 2) * t + s * Wt)
    74.08182206817179       # lognormal z=-1, ie. rndSND=-1, aka -1SD
    70.82203534678          # GBM z=-1, ie. rndSND=-1, aka -1SD
    
    "+1SD" :
    S0=100 ; u=0.0; s=0.3 ; t=1 ; rndSND=+1.0 ; S0 * exp(u * t + s * sqrt(t) * rndSND) ; Wt = sqrt(t) * rndSND; S0 * exp((u - s * s / 2) * t + s * Wt)
    134.9858807576003       # lognormal z=+1, ie. rndSND=+1, aka +1SD
    129.046162087289        # GBM z=+1, ie. rndSND=+1, aka +1SD
    
    4) Conclusion:
    The values for -1SD and +1SD differ (74.08 vs. 70.82 and 134.98 vs. 129.04).
    Since the values for lognormal are correct (74.08 and 134.98), then it follows that GBM is wrong. Q.E.D.

    Reason is the use of Ito's lemma, ie. the term "- s^2/2" in the GBM equation.
    This finding here could maybe have an impact also on BSM, where Ito's lemma gets used as well...

    See also
    https://en.wikipedia.org/wiki/Normal_distribution#Standard_normal_distribution
     
    Last edited: Aug 15, 2023
    #24     Aug 15, 2023
  5. Sergio123

    Sergio123

    Returns are normal. Prices are lognormal.

    Stock prices are always >=0.
     
    #25     Aug 15, 2023
  6. Right, but does it invalidate the above given proof?

    Btw, I've even a second proof using Monte Carlo simulation. Will soon post it too.
     
    #26     Aug 15, 2023
  7. Sergio123

    Sergio123

    I don't know. I didn't go through it. I don't use that implementation of it.
     
    #27     Aug 15, 2023
  8. Yes, there are many variations of GBM out there. I've tested many of them, most are just trash :)
    Just post the algorithm you use, I can analyse it.
     
    #28     Aug 15, 2023
  9. Sergio123

    Sergio123

    • The state x(t) of a geometric Brownian motion satisfies an Ito differential equation:

    • d x(t) = μ * x(t) dt + σ*x(t) dw(t), where w(t) follows a standard Wiener Process.
    • The state of x(t) follows a LogNormal Distribution of [(μ-[​IMG]) t+ Log[x0]]
    • The parameter μ can be any real number, and σ and x0 any positive real numbers.
    • The Wiener Process is a Brownian motion, continuous-time random walk, or integrated white Gaussian noise with a drift μ and volatility σ.
    • The state at time t of the Weiner process follows NormalDistribution[μ t,σ[​IMG]].
     
    #29     Aug 15, 2023
  10. You said yours is different, but IMO it's the same GBM as in #2 in my posting above, ie. the GBM at wikipedia.
    Or where do you see the difference?

    I think there is something missing in the following sentence & formula, ie. the Wiener process part is missing:
    Here's a screenhot showing also the missing part in your posting:

    Wolfram_GBM.png
     
    Last edited: Aug 15, 2023
    #30     Aug 15, 2023