Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tsferro2/f0dca2ebde8e83c787db422cdffa9c2c to your computer and use it in GitHub Desktop.
Save tsferro2/f0dca2ebde8e83c787db422cdffa9c2c to your computer and use it in GitHub Desktop.

Revisions

  1. tsferro2 created this gist Mar 10, 2022.
    27 changes: 27 additions & 0 deletions Geometric Brownian Motion time series simulation
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    import math
    import numpy as np
    import numpy.random as npr
    from pylab import plt, mpl

    # Geometric Brownian Motion (granual/steps)
    S0 = 100 # starting price
    r = 0.05 # short rate
    sigma = 0.25 # vol
    I = 10000 # simulations
    M = 50 # steps per sim
    dt = T / M
    S = np.zeros((M + 1, I))
    S[0] = S0
    for t in range(1, M + 1):
    S[t] = S[t - 1] * np.exp((r - 0.5 * sigma ** 2) * dt +
    sigma * math.sqrt(dt) * npr.standard_normal(I))

    plt.figure(figsize=(10, 6))
    plt.hist(S[-1], bins=50)
    plt.xlabel('index level')
    plt.ylabel('frequency');

    plt.figure(figsize=(10, 6))
    plt.plot(S[:, :10], lw=1.5)
    plt.xlabel('time')
    plt.ylabel('index level');