I generate 10000 random binomial paths for a stock whose price is from S(0) = 10 out to S(t) where t = 1 year. Assume geometric Brownian motion for the stock price with a drift of 15% per year and a volatility of 20%. I use 10000 equally spaced time steps of length along each path and $\Delta S = \mu S \Delta t \pm \sigma S \sqrt{\Delta t}$, where the + or – moves at each time step are generated at random with equal probability.
S = 10
S1 = []
mean = 0.15
sd = 0.2
for i in range(10000):
S = 10
for j in range(10000):
roll = np.random.rand()
if roll < 0.5:
S = S + mean*S/10000 + sd*S/100
else:
S = S + mean*S/10000 - sd*S/100
S1.append(S)
I use the above codes to simulate the GBM and my result is the same as the theoretical values. Mean should be $S(0)e^{\mu t}$ and the variance should be $S^2(0)e^{2\mu t}(e^{\sigma^2 t} - 1)$. But there is one question want me to calculate the inverse, which is $G(t) = 1/S(t)$. I consider that mean should be $\frac{1}{S(0)}e^{\mu t}$ and variance should be $\frac{1}{S^2(0)}e^{2\mu t}(e^{\sigma^2 t} - 1)$. Am I correct? But I'm not sure how to change my codes. I have tried to write down the following codes. But the result is far from the theoretical values mean = 0.116 and variance = 0.00055. Could someone explain where I'm doing wrong? Thank you very much.
S = 10
G1 = [1/10]
mean = 0.15
sd = 0.2
for i in range(10000):
S = 10
for j in range(10000):
roll = np.random.rand()
if roll < 0.5:
G = 1/S
S = S + mean*S/10000 + sd*S/100
G = G + mean*(1/S)/10000 + sd*(1/S)/100
else:
G = 1/S
S = S + mean*S/10000 - sd*S/100
G = G + mean*(1/S)/10000 - sd*(1/S)/100
G1.append(G)