import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
This is the stock price one time interval away (accumulated) using geometric Brownian motion: $$ S_T = S_t e^{(r - \frac{\sigma^2}{2})(T-t) + \sigma \sqrt{T - t} \epsilon} $$
def St(r, sigma, t):
ret = 1.0 * np.exp((r - 0.5 * sigma**2) * dt + sigma * np.sqrt(t[1]-t[0]) * np.cumsum(np.random.randn(len(t))))
return ret
Now let's plot in the interval $t\in[0,1]$ with r=1
or r=0.5
and for different sigma
t = np.linspace(0,1,200)
plt.plot(t, St(1, 0.2, t), label='$r=1$, $\sigma=0.2$')
plt.plot(t, St(1, 0.5, t), label='$r=1$, $\sigma=0.5$')
plt.plot(t, St(0.5, 0.5, t), label='$r=0.5$, $\sigma=0.5$')
plt.legend()