Skip to content

Forecasting Index Returns with Monte Carlo Simulation and Geometric Brownian Motion in Python

kangwijen

4 min read

How the model works

Monte Carlo simulation estimates possible outcomes of uncertain events. In finance, it's widely used for pricing derivatives, assessing risk, and forecasting asset prices (Pachamanova, 2012). Combined with the Geometric Brownian Motion (GBM) model, it can estimate possible paths for unpredictable stock prices.

Geometric Brownian Motion is a stochastic process commonly used to model how asset prices move over time. It assumes that price changes are random and follow a log-normal distribution (Silva & Shi, 2019). This assumption aligns with the efficient market hypothesis, which states that all known information is already reflected in current prices (Peng & Simon, 2024).

Geometric Brownian Motion accounts for both the predictable and unpredictable parts of price movement (Prasad et al., 2022). The predictable part is called the drift (µ), representing the average rate of return of the asset. While the unpredictable part is the volatility (σ), which captures the random fluctuations around the drift (Ermogenous, 2006). A mix of these two elements provides a probabilistic view of possible future prices.

Monte Carlo simulation generally follows three steps (Yusoff, 2023). First, we build a model by identifying the target variable (like future asset price) and the input variables that affect it (like return and volatility). Next, we define probability distributions for these inputs, often based on historical data. Finally, we run the simulation many times, each time generating random values for the inputs. Each run produces a possible price path. By averaging a large number of simulations, the Monte Carlo method minimizes variance and estimates the expected future price (Alrabadi & Aljarayesh, 2015).

The math behind Geometric Brownian Motion

To simulate index level using Monte Carlo methods, we use the Geometric Brownian Motion (GBM) model where the stochastic differential equation for it is (Brodd & Djerf, 2018):

We then use the analytical form of GBM to model the index level (Brodd & Djerf, 2018):

Translating it to Python

We fetch historical data of the IDX Composite Index (^JKSE) from 1994-2024 using the yfinance library. From the daily closing prices, we compute daily log returns:

Log returns are used because they are additive over time, making calculations easier.

python
import yfinance as yf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# 1. Download and preprocess
index = yf.download('^JKSE', start='1994-01-01', end='2024-12-31')
# Drop multi-index columns because it returns a multi-index DataFrame
if isinstance(index.columns, pd.MultiIndex):
    index = index.droplevel(1, axis=1)

# 2. Compute daily log returns and drop NaNs
index['log_ret'] = np.log(index['Close'] / index['Close'].shift(1))
index.dropna(subset=['log_ret'], inplace=True)

From the historical log returns, we estimate the average annual drift (μ) and volatility (σ) of the index. These are scaled to annual values:

The last closing price​ becomes the starting point for the simulation.

python
# 3. Estimate GBM parameters from history
S0    = index['Close'].iloc[-1]
mu    = index['log_ret'].mean() * 252
sigma = index['log_ret'].std()   * np.sqrt(252)
print(f"S0: {S0:.2f}, mu: {mu:.4f}, sigma: {sigma:.4f}")

# 4. Simulation setup
T       = 1        # years
n_steps = 252      # daily steps
n_paths = 100_000  # number of Monte Carlo paths
t       = np.linspace(0, T, n_steps)
dt      = T / n_steps

We then use the previous analytical form of GBM to model asset prices. We simulate 100,000 random paths over 252 trading days (1 year), then compute and plot the average path.

python
# 5. Simulate Brownian motion
Z   = np.random.normal(size=(n_steps, n_paths))
B_t = np.cumsum(Z * np.sqrt(dt), axis=0)

# 6. Apply GBM formula
S_t = S0 * np.exp((mu - 0.5 * sigma**2) * t[:, None] + sigma * B_t)

We then plot the mean of all simulated paths, which represents the expected future price under the GBM model.

python
plt.figure(figsize=(10, 6))
plt.plot(t, S_t.mean(axis=1), lw=2, label='Mean Path')
plt.title('Analytical Solution of GBM: Asset Price Simulation')
plt.xlabel('Time (Years)')
plt.ylabel('Asset Price')
plt.grid(True)
plt.legend()
plt.show()

The mean path generally slopes upward because the drift (μ) is positive, consistent with long-term historical growth in equity indices.

Limits of the model

This simulation is based on Geometric Brownian Motion (GBM), which assumes log-normal price behavior, constant volatility, and continuous market movement. These assumptions are mathematically convenient and widely used in academic and industry settings, but they do not always reflect real financial markets. Asset prices may experience abrupt jumps, volatility clustering, heavy tails, and structural breaks, all of which are absent from the GBM framework.

GBM remains a foundational model in quantitative finance. Its simplicity and analytical tractability make it a useful starting point for understanding the stochastic behavior of asset prices. A Monte Carlo simulation built on GBM gives a probabilistic view of potential future outcomes for exploratory analysis, risk management, and education.

For more realistic models, consider adding stochastic volatility (e.g., Heston model), jump-diffusion processes (e.g., Merton's model), or data-driven techniques such as regime-switching models and machine learning approaches.

References

Pachamanova, D. A. (2012). Monte Carlo Simulation in Finance. In Encyclopedia of Financial Models. https://doi.org/10.1002/9781118182635.efm0128 (opens in a new tab)

Silva, B. D., & Shi, S. S. (2019). Style Transfer with Time Series: Generating Synthetic Financial Data. arXiv (Cornell University). https://doi.org/10.48550/arxiv.1906.03232 (opens in a new tab)

Peng, C., & Simon, C. (2024). Financial Modeling with Geometric Brownian Motion. Open Journal of Business and Management, 12(2), 1240. https://doi.org/10.4236/ojbm.2024.122065 (opens in a new tab)

Prasad, K., Prabhu, B., Pereira, L., Prabhu, N., & Pavithra, S. (2022). Effectiveness of Geometric Brownian Motion Method in Predicting Stock Prices: Evidence From India. Asian Journal of Accounting and Governance, 18. https://doi.org/10.17576/ajag-2022-18-09 (opens in a new tab)

Ermogenous, A. (2006). Brownian Motion and Its Applications In The Stock Market. https://ecommons.udayton.edu/cgi/viewcontent.cgi?article=1010&context=mth_epumd (opens in a new tab)

Yusoff, M. I. M. (2023). Making Sense of Anything thru Analytics: Employees Provident Fund (EPF). Open Journal of Modelling and Simulation, 11(3), 51. https://doi.org/10.4236/ojmsi.2023.113004 (opens in a new tab)

Alrabadi, D. W. H., & Aljarayesh, N. I. A. (2015). Forecasting Stock Market Returns Via Monte Carlo Simulation:, The Case Of Amman Stock Exchange. المجلة الأردنية في إدارة الأعمال, 745. https://doi.org/10.35516/0338-011-003-010 (opens in a new tab)

Brodd, T., & Djerf, A. (2018). Monte Carlo Simulations of Stock Prices: Modelling the probability of future stock returns.