Skip to main content
The Risk-of-Ruin Equation

How to Run a Simple Monte Carlo Yourself

Pomegra Learn

How Do You Actually Run a Monte Carlo Simulation for Your Trading?

Monte carlo simulation steps are surprisingly straightforward, and you don't need advanced statistical software to run them. Whether you prefer Python, Excel, or even a simple calculator, the core algorithm remains the same: collect your historical returns, randomly resample them thousands of times, and measure how often your account hits zero. Learning to run your own monte carlo simulation hands-on builds intuition about path dependency and sequence risk in ways that reading formulas never can.

This article walks you through a complete monte carlo simulation steps process, from data preparation to interpreting results, with working examples you can replicate immediately. By the end, you'll have a functioning simulation in your preferred tool and confidence that you understand every number in your ruin probability estimate.

Quick definition: Running a monte carlo means executing an algorithm that repeatedly resamples historical returns, updates an account balance after each simulated trade, and tracks how many scenarios result in ruin, then divides ruin count by total trials to estimate your ruin probability.

Key takeaways

  • Gather your last 100–500 trade returns in a single column; this is your historical dataset
  • Set a starting capital, position size rule, and stopping condition (ruin threshold, usually zero or a minimum account size)
  • Build a loop that runs 10,000 times: shuffle your returns, simulate one trading sequence, record the outcome
  • Track maximum drawdown and final balance alongside ruin events to assess risk across scenarios
  • Validate results by comparing monte carlo ruin probability to formula-based estimates from prior chapters

Prerequisite: Collecting Your Trade Returns

Before running any simulation, you need clean historical data. This means your last N trades, recorded with their returns as decimal or percentage form. If you traded $50,000 and netted a $1,000 profit, that's a +2% return (or +0.02 in decimal). If you lost $2,000, it's −4%.

The ideal dataset is 100 to 500 trades. Fewer than 50 trades introduces high variability in your simulation; more than 1,000 trades may include regime shifts (old strategies, old market conditions) that no longer apply. Many traders use their last 100 or 200 trades as a middle ground.

Your data should be formatted like this:

Trade 1: 0.02     (2% profit)
Trade 2: -0.01 (1% loss)
Trade 3: 0.015 (1.5% profit)
Trade 4: -0.02 (2% loss)
...
Trade 100: 0.025 (2.5% profit)

If your broker provides P&L in dollars (e.g., $500 profit on a $25,000 account), convert to returns: 500 / 25,000 = 0.02, or 2%.

Step 1: Set Your Simulation Parameters

Before running monte carlo simulation steps, lock in three parameters:

  1. Starting Capital — Your initial account balance. For example, $50,000.
  2. Number of Trades per Trial — How many periods you want to simulate. Usually, this matches your historical data length (e.g., simulate 100 trades) or a planning horizon (e.g., simulate 50 trades into the future).
  3. Ruin Threshold — The account balance at which you stop trading and declare ruin. Usually zero or a minimum account size required for margin. If your minimum trading requirement is $5,000, set ruin threshold to $5,000.

Example parameters for a currency trader:

  • Starting Capital: $50,000
  • Trades per Trial: 100
  • Ruin Threshold: $0 (or $2,500 if you want to account for minimum margin)

Step 2: Build the Main Loop

The structure of monte carlo simulation steps is a loop that repeats for each trial. Pseudocode:

results = empty list to store outcomes

for trial = 1 to 10,000:
balance = starting_capital
max_drawdown = 0

for trade = 1 to trades_per_trial:
random_return = randomly select one return from your historical data
balance = balance * (1 + random_return)

if balance <= ruin_threshold:
record balance, max_drawdown, "RUIN"
stop this trial
end if
end for

if trial did not trigger ruin:
record balance, max_drawdown, "SURVIVED"
end if
end for

The key operation is the random selection: each trial picks a fresh random order of your historical returns. This is where bootstrap resampling happens.

Example in Python

Here's a working Python implementation you can copy and run:

import random

# Your historical trade returns (as decimals)
historical_returns = [
0.02, -0.01, 0.015, -0.02, 0.025, -0.005,
0.03, -0.015, 0.02, -0.01, 0.018, 0.005,
# ... add your 100+ real returns here
]

starting_capital = 50000
trades_per_trial = 100
ruin_threshold = 0
num_trials = 10000

ruin_count = 0
final_balances = []
max_drawdowns = []

for trial in range(num_trials):
balance = starting_capital
peak_balance = starting_capital
max_dd_trial = 0

for trade in range(trades_per_trial):
# Randomly select a return from history (with replacement)
selected_return = random.choice(historical_returns)
balance = balance * (1 + selected_return)

# Track maximum drawdown
if balance < peak_balance:
drawdown = (balance - peak_balance) / peak_balance
max_dd_trial = min(max_dd_trial, drawdown)
else:
peak_balance = balance

# Check for ruin
if balance <= ruin_threshold:
ruin_count += 1
final_balances.append(balance)
max_drawdowns.append(max_dd_trial)
break
else:
# Trial completed without ruin
final_balances.append(balance)
max_drawdowns.append(max_dd_trial)

# Calculate results
ruin_probability = ruin_count / num_trials
print(f"Ruin Probability: {ruin_probability:.4f} ({ruin_probability*100:.2f}%)")
print(f"Average Final Balance: ${sum(final_balances) / len(final_balances):.2f}")

# Percentiles
final_balances.sort()
percentile_5 = final_balances[int(0.05 * num_trials)]
percentile_25 = final_balances[int(0.25 * num_trials)]
percentile_50 = final_balances[int(0.50 * num_trials)]

print(f"5th Percentile Final Balance: ${percentile_5:.2f}")
print(f"25th Percentile Final Balance: ${percentile_25:.2f}")
print(f"50th Percentile Final Balance (Median): ${percentile_50:.2f}")

Run this code (replacing the historical_returns list with your own data), and it outputs your monte carlo simulation results immediately.

Example in a Spreadsheet

If you prefer a spreadsheet approach, here's a simplified Excel structure:

Column A: Historical returns (rows 1–100, your 100 trades) Columns B–D: Trial 1, Trial 2, Trial 3 (one column per trial, or use 10 trials if you're teaching yourself)

In cell B1, use: =INDEX($A$1:$A$100,RANDBETWEEN(1,100)) This randomly selects one return from your historical data.

In B2: =$B$2 * (1 + B1) — Wait, adjust this. If B2 is your balance after trade 1, put a starting value in B1:

  • B1 (starting balance): 50000
  • B2 (balance after trade 1): =B1 * (1 + INDEX($A$1:$A$100,RANDBETWEEN(1,100)))
  • B3 (balance after trade 2): =B2 * (1 + INDEX($A$1:$A$100,RANDBETWEEN(1,100)))
  • Copy B3 down to row 101 (100 trades).

After you build one trial column, copy it across to create 10 or 100 trial columns. Count how many final balances (at row 101) are <= 0. That count divided by total trials is your ruin probability.

The spreadsheet approach is slower for 10,000 trials (spreadsheets often freeze or time out), but it's excellent for teaching yourself the mechanics of monte carlo simulation steps.

Step 3: Interpret the Output

After your simulation completes, you have three main outputs:

  1. Ruin Probability — Count of ruin trials ÷ total trials. If 150 out of 10,000 trials hit zero, your ruin probability is 1.5%.

  2. Distribution of Final Balances — Sort all final balances from smallest to largest. The 5th percentile tells you the balance that 95% of scenarios exceed; the 95th percentile tells you the balance that the best 5% of scenarios achieve. A wide distribution (e.g., 5th percentile = $30k, 95th percentile = $120k) indicates high variability; a narrow distribution suggests predictable outcomes.

  3. Maximum Drawdown Distribution — Similarly, sort the worst drawdown from each trial. The median max drawdown across all trials tells you a typical bad run you might experience. The 95th percentile max drawdown shows the worst drawdown in the best 5% of scenarios.

A complete output summary might look like this:

Ruin Probability:         1.86%
Average Final Balance: $64,250
5th Percentile Balance: $48,600
25th Percentile Balance: $57,300
50th Percentile Balance: $64,500
75th Percentile Balance: $72,100
95th Percentile Balance: $85,400

Median Max Drawdown: -12.5%
95th Percentile Max DD: -28.3%

This output tells you: there's a ~2% chance of ruin, your median outcome is roughly +28% gain, and you should expect a typical worst drawdown of around 12–13%.

Decision Tree for Interpreting Results

Real-World Example: A Day Trader's Monte Carlo

A day trader collected 150 trades over the last three months:

  • Win rate: 58% (87 winning trades)
  • Losing trades: 63
  • Average winner: +0.8%
  • Average loser: −0.6%
  • Starting capital: $25,000

They run a monte carlo with 10,000 trials, simulating 150 trades per trial (matching their historical length) with a ruin threshold of $0.

Results:

  • Ruin Probability: 2.34%
  • Median Final Balance: $31,400
  • 5th Percentile Final Balance: $23,100
  • 95th Percentile Final Balance: $42,800
  • Median Max Drawdown: −9.2%
  • 95th Percentile Max Drawdown: −22.5%

Interpretation: In 98% of scenarios, the trader's account survives the next 150 trades. The median outcome is a ~25% gain. However, in the worst-case scenarios (5th percentile), the trader ends with only $23,100—a loss relative to starting capital. The typical worst drawdown is about 9%, but in extreme scenarios (95th percentile), a drawdown could reach 22.5%. This trader has a viable strategy, but should ensure their capital can withstand a potential 22–23% drawdown without forced liquidation or psychological breakdown.

Validating Your Monte Carlo Against Formulas

A sanity check: compare your monte carlo ruin probability to the risk-of-ruin formula from earlier chapters. They should be similar (within 1–2 percentage points). If they differ dramatically, investigate:

  • Are your historical returns correctly formatted (decimals, not percentages)?
  • Did you accidentally include commissions or slippage twice?
  • Does your historical data include trades from a different strategy or market regime?

If the formula predicts 2% ruin and monte carlo shows 8%, your historical data likely contains bias or regime effects the formula doesn't account for. That's valuable information: it suggests your strategy is less stable than the formula implies.

Common Mistakes

  1. Forgetting to shuffle returns for each trial — If you always use the same order of historical returns, you're not running a monte carlo; you're just replaying history. Ensure each trial uses a random resample.

  2. Using absolute dollar returns instead of percentage returns — If you resample $500 profit on a $25k account the same way you resample $500 profit on a $100k account, you're breaking the proportional risk structure. Always convert to percentages (returns) first.

  3. Contaminating your historical data — Including trades from before a strategy change, or from a market regime that no longer exists, poisons your monte carlo results. Use only truly representative, recent data.

  4. Misunderstanding ruin threshold — Setting ruin threshold to $0 is mathematically correct but unrealistic if your broker has margin requirements or you personally can't trade with $100 left. Set it to the minimum account size you actually need.

  5. Running too few trials — 100 or 500 trials introduce high sampling variability. Aim for at least 5,000; 10,000 is the practical standard.

FAQ

How Do I Run a Monte Carlo If My Trade Data Is In My Broker's Platform?

Export your trade history as a CSV file. Most brokers (Interactive Brokers, TD Ameritrade, Crypto exchanges) allow export. Then extract the P&L column, convert to returns, and paste into your Python script or spreadsheet.

What If Some Trades Are in Cryptocurrency and Others in Forex? Can I Mix Them?

Mixing highly different markets in one monte carlo is risky because their return distributions and correlations differ. Best practice: run separate monte carlos for each market, then combine them using portfolio weighting if you trade multiple instruments simultaneously.

Should I Include Commissions and Slippage in My Historical Returns?

Yes. If your historical P&L figures are before commissions, subtract them. For example, a $500 profit on a $50k account with $50 in commissions should be recorded as ($500 - $50) / $50,000 = 0.9%, not 1%.

What If I Only Have 30 Trades? Can I Still Run a Monte Carlo?

Technically yes, but the estimate is unreliable. With 30 trades, random resampling produces high variability in ruin probability. Consider running the simulation but also comparing to the formula-based ruin estimate, and be cautious about over-interpreting results. If possible, collect more data before making large position sizing decisions.

How Often Should I Rerun My Monte Carlo?

Rerun it monthly or quarterly as you accumulate new trades. Each new trade refines your historical distribution and changes the ruin probability estimate. A strategy that showed 1% ruin with 100 trades might show 3% ruin once you have 200 trades and include a regime shift in your data.

Can Monte Carlo Predict Black Swan Events?

No. Monte Carlo is based on historical resampling, so it cannot predict unprecedented events (a stock gaps down 50% on bankruptcy news, or a flash crash hits your pair). Black swans by definition fall outside your historical distribution. Scenario analysis is better for stress-testing against tail events.

Summary

Running a monte carlo simulation demystifies ruin risk by putting you in direct control of the calculation. Whether you choose Python, a spreadsheet, or even a dedicated tool, the algorithm is identical: gather historical returns, randomly resample them thousands of times, measure ruin frequency, and extract percentiles. The hands-on experience of building your own simulation—seeing how a few bad trades bunched together can wipe out an account, or how rare ruin truly is across thousands of scenarios—builds intuition that reading formulas or articles alone cannot provide.

The real power emerges when you compare your monte carlo results to your formula-based estimates, adjust parameters, and rerun simulations as you collect new trades. Over time, your monte carlo becomes a living risk dashboard, tracking not just whether your strategy survives, but how and under what conditions it might fail.

Next

Why Positive Expectancy Is Not Enough