Every so often someone asks how much of an account to risk per trade, and the thread fills up with opinions. The honest answer is arithmetic, and it fits in a file small enough to read over coffee — so I wrote it down and put it on GitHub.

github.com/pipatlas26/risk-of-ruin — MIT, zero dependencies, deterministic with a seed.

The model, stated up front

Fixed-fractional sizing: you risk riskPct of current equity per trade. Each trade wins with probability winRate, paying avgWinR (in R, where 1 R = the amount risked), or loses exactly 1 R. "Ruin" = equity falls ruinThreshold below its running peak — how funded-account and personal drawdown limits actually work.

const { runRiskOfRuin } = require('./risk-of-ruin.js'); runRiskOfRuin({ winRate: 0.50, // 50% win rate avgWinR: 1.5, // winners average 1.5R riskPct: 0.01, // risk 1% of equity per trade trades: 200, ruinThreshold: 0.30, // ruin = 30% drawdown from peak runs: 10000, seed: 42, // deterministic output }); 
risk of ruin : 0.01% finished ahead : 99.68% expectancy : 0.250 R per trade median final equity: 162.2% of start longest losing streak seen: 22 worst drawdown : 30.67% 

Three things the simulation makes obvious

1. Streaks are longer than intuition. Over 200 trades at a 50% win rate, the worst losing streak across a 10,000-run sample is 19–23 trades (measured across ten seeds). People size as if their worst streak is five. Size for twenty.

2. The risk percentage, not the edge, decides survival. Same 50% / 1.5R edge:

Risk per trade Risk of ruin (30% limit)
1% ~0.01%
5% ~84.9%

The expectancy is identical in both rows (0.25R). One is a business; the other is a countdown.

3. Negative expectancy can't be sized away. 40% at 1.5R is exactly zero. 38% at 1.5R is −0.05R per trade — a slow, certain bleed that no lot-size trick repairs. Compute expectancy before optimising anything.

Why the code, not just a calculator

A web calculator is a black box with a nicer font. A 120-line module with the assumptions in the header is something you can audit, fork into your own journal or bot, or argue with by changing one line. If you think streaks cluster (they do — news weeks, regime shifts), the model is honest about being an approximation: expect live drawdowns slightly deeper than it says.

There's a browser version with the same model at pipatlas.com/tools/risk-of-ruin, and a free trade log that records everything in R, so you can measure your real win rate before trusting any of it: the spreadsheet.

Not financial advice

It's arithmetic on numbers you supply. Trading on margin can lose more than you deposit. The only claim here is that the simulation does exactly what the header says it does.

I build PipAtlas, a free no-signup forex toolkit — the calculators show their own formulas, which is the whole point. Repo issues welcome.
`