Monte Carlo Risk Simulation — Modeling Portfolio Outcomes
Monte Carlo simulations let you model 100,000+ potential future paths of your portfolio, quantifying risk metrics like Value at Risk (VaR) and expected shortfall. Instead of assuming a single outcome, you see the distribution of possibilities.
Example: Run 100k simulations of your trading strategy. You'll see: 68% of outcomes profit $10-$50, 25% lose $10-$30, 5% lose $50-$200, and 2% profit $100+. Now you understand your risk profile.
Basic Geometric Brownian Motion (GBM)
Model future prices as random walks with drift and volatility:
import numpy as np
def simulate_price_paths(S0, mu, sigma, T, dt, n_sims=10000):
steps = int(T / dt)
paths = np.zeros((n_sims, steps))
paths[:, 0] = S0
for i in range(1, steps):
Z = np.random.normal(0, 1, n_sims)
dS = mu * paths[:, i-1] * dt + sigma * paths[:, i-1] * np.sqrt(dt) * Z
paths[:, i] = paths[:, i-1] + dS
return paths
Portfolio Risk Metrics
Value at Risk (VaR)
The loss you'd exceed in only 5% of scenarios (95% confidence):
def calculate_var(simulations, confidence=0.95):
pnl = simulations[:, -1] - simulations[:, 0]
var = np.percentile(pnl, (1 - confidence) * 100)
return var
Expected Shortfall (CVaR)
Average loss in the worst 5% of cases:
def calculate_cvar(simulations, confidence=0.95):
pnl = simulations[:, -1] - simulations[:, 0]
var_threshold = np.percentile(pnl, (1 - confidence) * 100)
worst_5_pct = pnl[pnl <= var_threshold]
cvar = np.mean(worst_5_pct)
return cvar
Strategy-Specific Simulation
Simulate your actual trading rules, not just price paths:
def simulate_strategy(capital, win_rate, avg_win, avg_loss, trades_per_day=10, days=30, n_sims=10000):
results = np.zeros(n_sims)
for sim in range(n_sims):
equity = capital
n_trades = trades_per_day * days
for _ in range(n_trades):
if np.random.rand() < win_rate:
pnl = np.random.normal(avg_win, avg_win * 0.2)
else:
pnl = -np.random.normal(avg_loss, avg_loss * 0.2)
equity += pnl
if equity < capital * 0.5:
break
results[sim] = equity
return results
Stress Testing with Smart Money Signals
Model worst-case scenarios when Smart Money confidence drops:
def stress_test_scenarios(base_win_rate):
scenario_normal = simulate_strategy(10000, win_rate=base_win_rate)
scenario_medium = simulate_strategy(10000, win_rate=base_win_rate * 0.95)
scenario_veto = simulate_strategy(10000, win_rate=0.45)
return {
'normal': {'var': np.percentile(scenario_normal, 5), 'mean': np.mean(scenario_normal)},
'medium': {'var': np.percentile(scenario_medium, 5), 'mean': np.mean(scenario_medium)},
'veto': {'var': np.percentile(scenario_veto, 5), 'mean': np.mean(scenario_veto)}
}
Interpretation
From 10k simulations, you learn:
- Median outcome (50th percentile)
- Best case (95th percentile)
- Worst case (5th percentile)
- Probability of ruin (equity < 0)
- Expected drawdown length
Stress-test strategies with Smart Money signals
Understand portfolio risk under normal, deteriorating, and VETO Smart Money conditions. Our API gives you the signals; Monte Carlo models the outcomes.
Risk Model Today →