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

kangwijen

kangwijen

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

An Overview

Monte Carlo simulation is a statistical method used to estimate possible outcomes of uncertain events. In finance, it’s widely used for pricing derivatives, assessing risk, and forecasting asset prices (Pachamanova, 2012). Because stock prices often behave unpredictably, combining Monte Carlo simulation with the Geometric Brownian Motion (GBM) model can be a powerful approach for making predictions.

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 and by averaging the results of a large number of simulations, the Monte Carlo method minimizes variance and provides an estimate of the expected future price (Alrabadi & Aljarayesh, 2015). In short, the approach involves simulating numerous possible scenarios and then analyzing the distribution of outcomes to make predictions.

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()

Mean Price of Monte Carlo Simulations with GBM Model for IHSG

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

Final Thoughts

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

Nevertheless, GBM remains a foundational model in quantitative finance. Its simplicity, analytical tractability, and intuitive structure make it a useful starting point for understanding the stochastic behavior of asset prices. The Monte Carlo simulation built on GBM provides a probabilistic framework to explore a wide range of potential future outcomes, which is valuable for exploratory analysis, risk management, and educational purposes.

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

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

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

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

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

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

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

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