Monte Carlo symulacja strategii — risk visualization

Ostrzeżenie · YMYL Ten artykuł ma charakter wyłącznie edukacyjny i nie stanowi rekomendacji inwestycyjnej. Handel na rynku Forex wiąże się z wysokim ryzykiem utraty kapitału — według ESMA 74–89% rachunków detalicznych traci pieniądze.

Krzysiek test strategy w demo: 55% WR, expectancy +€19/trade, +€3,800 expected rocznie. Live 5% risk per trade = blew €15k account 6 mies. Re-tested Monte Carlo 1000 sims: ruin prob 25%, max DD 60%. Position sizing wrong. Reduced 1% = ruin 0.1%, DD 10%. Rok 2 profitable. Tu pokazujemy Monte Carlo framework.

Czym Monte Carlo

Monte Carlo = randomization 1000+ scenariuszy z same statistics dla risk visualization.

Setup parameters

Monte Carlo inputs
Win rate55% (e.g.)
Avg win€100
Avg loss€80
Trades/rok200
Starting capital€10,000
Expectancy/trade+€19
Expected yearly+€3,800 (deterministic)

Simulation outputs

1000 sims same statistics
Median final+€3,750 (close to expected)
Worst 5%+€500
Worst 1%-€800
Best 5%+€7,500
Best 1%+€10,000
Range15× variance same strategy
LessonSame edge = different outcomes

Position sizing optimization

Risk % comparison
0.5% riskMedian €11k, DD 5%, ruin 0%
1% riskMedian €12k, DD 10%, ruin 0.1%
2% riskMedian €15k, DD 22%, ruin 2%
3% riskMedian €18k, DD 38%, ruin 8%
5% riskMedian €25k, DD 60%, ruin 25%
Sweet spot1-2% (max growth, ruin < 1%)

Excel implementation

  1. A1 = WR (0.55), A2 = avg win (100), A3 = avg loss (-80), A4 = trades (200)
  2. B1 = IF(RAND() < A1, A2, A3) — symulates 1 trade outcome
  3. C1 = A5 + B1 — equity update
  4. Drag formuły 200 rows = 1 simulation
  5. Copy column B-C × 1000 = 2000 cols = 1000 sims
  6. =PERCENTILE(final_equities, 0.5) = median, 0.05 = worst 5%, 0.01 = worst 1%
  7. F9 regenerates random = new 1000-sim run

Python implementation

Python bardziej powerful — full code possible 30 lines:

  • import numpy as np
  • np.random.random(trades) < wr → boolean array
  • np.where(boolean, avg_win, avg_loss) → outcomes
  • np.cumsum(outcomes) → equity curve
  • Loop 1000× → results list
  • np.percentile dla analysis
  • matplotlib visualization spaghetti plot

Kelly criterion comparison

Kelly formula optimal mathematical: Kelly% = WR - (1-WR)/(avg win / avg loss).

55% WR, R/R 1.25 = Kelly 19%. Pełny Kelly = high variance. "Half Kelly" 9.5% recommended.

9.5% still TOO HIGH dla retail (psychological + DD tolerance). Use 1-2% per trade.

„Monte Carlo NIE optional — to standard pro level analysis. Same strategy 1000× = 1000 different equity curves. Median ≠ guaranteed. Plan around worst-case 5%, NIE median. 1% risk = ruin < 1%. 5% risk = ruin 25%."

Bootstrap z real history

Advanced: zamiast assumed distribution, use REAL trade history (100+ trades). Bootstrap = random sampling z replacement.

  • Step 1: gather 100+ trades P/L
  • Step 2: randomly sample 200 trades z replacement
  • Step 3: compute equity curve
  • Step 4: repeat 1000×
  • Step 5: analyze distribution

Bootstrap captures REAL trade distribution (fat tails, clustering). More accurate niż parametric simulation.

Krzysiek case

Krzysiek Monte Carlo discovery
Original demo55% WR, +€19/trade expectancy
Live 5% riskBlown €15k account 6 mies.
Monte Carlo 5%Ruin prob 25%, DD 60%
Reduced 1% riskRuin 0.1%, DD 10%
Rok 2+€3,500 profit, stable
LessonMonte Carlo BEFORE going live = €15k saved

Wnioski

Monte Carlo simulation = randomization 1000+ scenariuszy same statistics. Visualization risk strategii.

Insight: same expectancy +€19/trade = +€500 do +€7,500 yearly range. NIE deterministic.

Position sizing optimization main application. Test 0.5%, 1%, 2%, 3%, 5% risk per trade.

Sweet spot 1-2% risk = ruin prob < 1%, decent growth.

5% risk = ruin 25%. NIE viable long-term.

Excel implementation simple: RAND() + IF + cumulative. 1000 sims doable.

Python more powerful: numpy + matplotlib, 30 lines kodu, advanced features (bootstrap, regime changes).

Kelly criterion: mathematical optimal, ale pełny too aggressive. Half Kelly still high. Use 1-2%.

Bootstrap real history: more accurate niż parametric (captures fat tails, clustering).

Krzysiek case: 5% risk live = blew €15k. Monte Carlo discovery: ruin 25%. Reduced 1% = profitable rok 2. €15k saved jeśli simulated BEFORE.

Powiązane: equity curve analiza visualization, expectancy formula baseline, maximum drawdown risk metric.

Jarosław Wasiński
O autorze

Jarosław Wasiński

Redaktor naczelny MyBank.pl · Analityk finansowy i rynkowy

Niezależny analityk i praktyk z ponad 20-letnim doświadczeniem w sektorze finansowym. Twórca i redaktor naczelny portalu MyBank.pl, działającego od 2004 roku. Analiza fundamentalna rynków walutowych i makroekonomicznych od 2007 roku.

Źródła i bibliografia

  1. Ralph Vince Mathematics of Money Management · Monte Carlo classic www.amazon.com ↗
  2. Van Tharp Trade Your Way to Financial Freedom · practical application vantharp.com ↗
  3. NumPy documentation Random sampling · Python implementation numpy.org ↗

Najczęstsze pytania

Czym Monte Carlo simulation?

Monte Carlo = method probabilistic analysis. Nazwa od Monaco casino, randomization. Trading application: zamiast jednej historical sequence trades, generate 1000+ random sequences z TĄ SAMĄ statystyką (WR, avg win, avg loss). Każda sequence = different equity curve. Distribution outputs = realistic expectations. Why important: historical backtest = JEDNA realization. Variance massive. Same strategy może realize 100 different paths next year. Monte Carlo shows ALL possibilities. Example: strategia 55% WR, avg win €100, avg loss €80, 200 trades/rok. Expectancy +€19/trade = +€3,800 expected rok. ALE Monte Carlo 1000 sims: median = +€3,750 (close to expected). Worst 5% = +€500. Worst 1% = -€800. Best 5% = +€7,500. Range MASSIVE despite same expectancy. Key insight: profit NIE deterministic. Same edge może yield +€500 lub +€7,500 rocznie based luck. Need 5+ lat data dla confidence interval. Common misconception: "My strategy made €5k last year, will make €5k next year." Reality: range €1k-€10k possible same strategy.

Excel Monte Carlo setup?

Simple Monte Carlo Excel (no VBA needed): Setup: A1 = WR (e.g. 0.55). A2 = avg win (e.g. 100). A3 = avg loss (e.g. -80). A4 = trades (e.g. 200). A5 = starting capital (e.g. 10000). Row 1 (trade 1): B1 = IF(RAND() < A1, A2, A3). Simulates 1 trade outcome. Equity: C1 = A5 + B1. Subsequent: B2 = IF(RAND() < A1, A2, A3), C2 = C1 + B2. Drag down 200 rows. Final equity: C200 = final balance for 1 simulation. Multiple sims: copy formula B-C 1000 times (column B-C, columns D-E, F-G, etc.). 1000 simulations = 2000 columns. Excel handles OK. Analysis: =PERCENTILE(final_equities, 0.5) = median. =PERCENTILE(final_equities, 0.05) = worst 5%. =PERCENTILE(final_equities, 0.01) = worst 1%. Max DD: for each sim, compute peak-to-trough drawdown. Distribution of max DD. Random regen: F9 key regenerates ALL random numbers. Each press = new 1000-sim run. Limitation: assumes independence trades (NIE clustered drawdowns). Real markets clustered. Add correlation factor advanced.

Python Monte Carlo implementation?

Python Monte Carlo bardziej powerful niż Excel. Libraries: numpy (random sampling), matplotlib (visualization), pandas (data handling). Code structure: import numpy as np. Define parameters: wr=0.55, avg_win=100, avg_loss=-80, trades=200, sims=1000. Function: def simulate_strategy(wr, avg_win, avg_loss, trades): trades_outcomes = np.where(np.random.random(trades) < wr, avg_win, avg_loss). equity = 10000 + np.cumsum(trades_outcomes). return equity. Run sims: results = [simulate_strategy(0.55, 100, -80, 200) for _ in range(1000)]. Analysis: final_equities = [r[-1] for r in results]. median = np.median(final_equities). worst5 = np.percentile(final_equities, 5). worst1 = np.percentile(final_equities, 1). max_dds = [max_drawdown(r) for r in results]. Visualization: matplotlib plot all 1000 equity curves overlap + percentile bands. Spaghetti plot.

Advanced features: (1) Variable WR (drift over time). (2) Cluster drawdowns (regime changes). (3) Position sizing optimization (test multiple risk %). (4) Bootstrap from REAL trade history (NIE assumed distribution).

Position sizing optimization?

Position sizing optimization = main Monte Carlo application. Test multiple risk %: 0.5%, 1%, 2%, 3%, 5% per trade. Run 1000 sims each. Compare outcomes: 0.5% risk: median equity €11k, max DD 5%, ruin prob 0%. Slow growth. 1% risk: median €12k, max DD 10%, ruin prob 0.1%. Sweet spot most strategies. 2% risk: median €15k, max DD 22%, ruin prob 2%. Aggressive but viable. 3% risk: median €18k, max DD 38%, ruin prob 8%. High risk. 5% risk: median €25k, max DD 60%, ruin prob 25%. Likely blow-up. Decision framework: Goal = max growth WHILE keeping ruin prob < 1%. Usually 1-2% risk per trade. Beyond = exponential ruin risk. Kelly criterion: optimal mathematical position sizing. Formula: Kelly% = WR - (1-WR)/(avg win / avg loss). 55% WR, R/R 1.25 → Kelly 19%. ALE pełny Kelly = high variance. "Half Kelly" (9.5%) recommended. Still too high dla retail. Use 1-2% per trade. Real-world example: Krzysiek tested strategy 5% risk per trade w live = blew €15k account 6 mies. Re-tested Monte Carlo = ruin prob 25%. Reduced 1% = profitable rok 2.

Pogłębij temat · pełny przewodnik