import numpy as np
import matplotlib.pyplot as plt
def simulate_geometric_random_walk(S0, T=2, N=1000, mu=0.1, sigma=0.05):
dt = T / N
t = np.linspace(0, T, N)
W = np.random.standard_normal(size=N)
# N(0,dt) = sqrt(dt)
W = np.cumsum(W) * np.sqrt(dt)
X = (mu - 0.5 * sigma**2) * t + sigma * W
S = S0 * np.exp(X)
print(W)
return t, S
plt.figure(figsize=(12, 5))
t, S = simulate_geometric_random_walk(100)
plt.plot(t, S, color='steelblue', lw=1.2)
plt.title(f'Geometric Brownian Motion μ=0.1 σ=0.05')
plt.xlabel('Time (years)')
plt.ylabel('Price')
plt.grid(True, alpha=0.3)
plt.show()
if __name__ == "__main__":
simulate_geometric_random_walk(10)
Code
29 lines
1
Reposts
5
Likes
0
Replies
No replies yet. Be the first to respond!