Simulating stock market returns using Monte Carlo › 3. Generating Random Returns

Michael BrenndoerferJuly 19, 20251 min read
Simulating stock market returns using Monte Carlo › 3. Generating Random ReturnsOne section · Sections in this article4 / 8 ↓
Reading tools Definitions & inline links

Toggle tooltip visibility. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The Heart of Monte Carlo Simulation

Thousands of possible future scenarios will be generated by randomly sampling investment returns from a normal distribution. This is the core of Monte Carlo simulation:

Key Insight: Annual returns are assumed to follow a normal distribution with:

Understanding the Output Structure

  • Rows: Each row represents one possible future scenario (simulation path)
  • Columns: Each column represents a year in the 10-year horizon
  • Values: Each value is a randomly sampled annual return for that year and scenario
In[3]:
Code
# Setting up reproducible random number generation for consistent results
rng = np.random.default_rng(seed=42)

# Generating random annual returns for all simulation paths
# Shape: (N_ITER, YEARS) = (10,000 scenarios × 10 years)
annual_returns = rng.normal(loc=MU, scale=SIGMA, size=(N_ITER, YEARS))

print(f"Generated Returns Matrix:")
print(f"   Shape: {annual_returns.shape}")
print(f"   Each row = one possible 10-year future")
print(f"   Each column = returns for a specific year across all scenarios")
print(f"\nSample of first 5 scenarios (first 5 years):")
print(pd.DataFrame(annual_returns[:5, :5], 
                  columns=[f'Year {i+1}' for i in range(5)],
                  index=[f'Scenario {i+1}' for i in range(5)]).round(3))
Out[3]:
Console
Generated Returns Matrix:
   Shape: (10000, 10)
   Each row = one possible 10-year future
   Each column = returns for a specific year across all scenarios

Sample of first 5 scenarios (first 5 years):
            Year 1  Year 2  Year 3  Year 4  Year 5
Scenario 1   0.126  -0.076   0.193   0.221  -0.213
Scenario 2   0.212   0.197   0.090   0.249   0.150
Scenario 3   0.052  -0.022   0.263   0.057   0.016
Scenario 4   0.401   0.019   0.003  -0.042   0.172
Scenario 5   0.191   0.161  -0.020   0.115   0.098