Skip to content

Instantly share code, notes, and snippets.

@dirkolbrich
Last active July 23, 2018 16:41
Show Gist options
  • Save dirkolbrich/aa4c9790a7126e85492e1277f4fbb7ed to your computer and use it in GitHub Desktop.
Save dirkolbrich/aa4c9790a7126e85492e1277f4fbb7ed to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
def geometric_brownian(years, drift, sigma, startPrice):
T=years
mu = drift
simga = sigma
S0 = startPrice
dt = 0.01
N = round(T/dt)
t = np.linspace(0, T, N)
print(len(t))
W = np.random.standard_normal(size = N)
W = np.cumsum(W)*np.sqrt(dt)
X = (mu-0.5*sigma**2)*t + sigma*W
S = S0*np.exp(X)
return t, S
t1, S1 = geometric_brownian(10, 0, 0, 100)
plt.plot(t1, S1)
t1, S1 = geometric_brownian(10, -0.1, 0.02, 100)
plt.plot(t1, S1)
t1, S1 = geometric_brownian(10, 0, 0.05, 100)
plt.plot(t1, S1)
t1, S1 = geometric_brownian(10, 0.1, 0.1, 100)
plt.plot(t1, S1)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment