Reproducing Geometric Brownian Motion Simulations with a Fixed Seed
Summary
The document addresses why repeated geometric Brownian motion simulations produce different price paths, even when the model inputs remain unchanged. The randomness comes from newly drawn Brownian shocks on each run. The accepted response gives a practical reproducibility method: initialize the random number generator with a fixed seed so that it produces the same sequence of random draws and therefore the same simulated path.
The question frames repeatability as a way to compare a simulated historical path with observed prices and use a good-fitting path for future forecasting. A fixed seed only makes a particular random realization repeatable; it does not make that path a reliable forecast or validate the model. The document supplies code context but no backtest results, forecast evaluation, or discussion of parameter estimation. Assessing a stochastic model requires evaluating its assumptions and performance across many paths, rather than selecting one that happens to fit past data.
Key ideas
- A GBM simulation changes across runs because its random shocks are redrawn.
- Fixing the random number generator seed reproduces the same sequence of shocks.
- A repeatable simulated path is not evidence that it forecasts future prices accurately.
- Model assessment should consider multiple simulated paths and out-of-sample performance.
Tags
Full text
# stock price path simulation using GBM, is it possible to run the same simulation over and over again?
# 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))
#or dt instead of T
# 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)
```
## Answer by ir7 (score 1, accepted)
https://quant.stackexchange.com/a/60900
Fix the RNG (random number generator)'s seed. This article from sharpsightlabs.com is accessible and illuminating.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.