# stock price path simulation using GBM, is it possible to run the same simulation over and over again?

When I simulate a stock's price path using geometric brownian motion I am sometimes able to get a pretty good forecast that fits the real values very well. But if I run the simulation again, the results are different. This is probably due to the random process of brownian motion.

Is there a way to run the same simulation (the one that fit the actual values well) over and over again without getting different results?

This is good when you are actually trading. Say for example you can run a test on some past data and then compare it with the real values to see if the model performed well or not. If it did, then you can use the same model for a future forecast in which you are going to buy and/or sell. But if the results are different on every simulation, then if you wish to do future forecast, you won't be able to test it with real data, since you are forecasting the future for which there is no data.

Here is my code. Half the time fits the data pretty, the other half not so.

#from __future__ import division
from random import gauss
from math import exp, sqrt
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np

def generate_asset_price(S,v,r,T):
return S * exp((mu - 0.5 * v**2) * T + v * sqrt(T) * gauss(0,1.0))

# return S * exp((mu - 0.5 * v**2) * T + v * sqrt(T) * gauss(0,1.0))

S0 = 12.2 # underlying price
v = 0.114764067

mu = -0.002773523

dt = 0.01 # 1 day
T = 20
n = int(20) # number of steps

S_path=[]
S=S0 # starting price
for i in xrange(1,n+1):
S_t = generate_asset_price(S,v,mu,dt)
S= S_t
S_path.append(S_t)

• Hi, some questions: When you say that "half the time fits the data pretty", do you mean that you simulate a new path until the path you have just simulated resembles the historically observed price path in some way? If so, do you assess this by inspection? And then you use that price path (and its 'future realizations') for some time until the quality of the resemblance deteriorates? Could you please elaborate a bit more on these aspects? If that is truly the case, and without delving into the many conceptual shortcomings of this, the answer from ir7 is indeed the way to go. – Kermittfrog Feb 3 at 8:59
• ...You simply play with the random number seed until the resemblance is "good". You then store this number and re-use it whenver you want to produce the exact same path again. Alternatively, you could simply store the path (and its future realizations) to file and load from that file; but that does not answer your specific question. – Kermittfrog Feb 3 at 9:00
• Yes, that is correct. I run the simulations until I get a path that fits historical values. I'm assuming that, with the seed value that fits that data, I can run future simulations and they will also fit the actual data. Yes I asses this by inspection, I plot the historical prices together with the simulation. Ir7, has answered my question nicely. But feel free to add some comments. – PlatinumMaths Feb 3 at 18:45
• What you are effectively suggesting is to a series of (identical) coins for as long as the history of the last $N$ flips look like something you look for. You then assume that the next flip should be representative of what you are looking for... That sounds dangerously foolish! – Kermittfrog Feb 4 at 8:58
• What would you suggest then? If the simulation that got what I looked for worked well on the not too distant past, say week before. Then why should another simulation with the same parameters not perform equally well? (obviously a different mu and sigma value) I'm not looking for precise forecast. I'm after a general direction of the price path and I think that a good GBM simulation can accomodate that. That way I can trade accordingly. – PlatinumMaths Feb 4 at 20:13