Advanced

Managing risk and drawdown

Risk management is what keeps a strategy alive long enough to find out if it's any good. Drawdown is the drop from a peak to a trough, and position sizing decides how much to put on each bet. Both exist for one reason: so one bad streak can't end the game.

What you will see

Risk per trade (1%): $1000.00 Shares sized: 200

About 2 min of reading

Quick check

Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.

Try It

A strategy is only as good as its worst moment, so I measure the biggest drop from a peak to a trough and size each trade to a small fixed fraction of the account, proving one bad streak cannot end the game.

1

I walk an equity curve tracking the running peak, then print the largest peak-to-trough drop as a percentage so the real downside is visible before any returns are celebrated.

equity = [100000, 102000, 99000, 110000, 105000, 70000] peak = equity[0] max_dd = 0.0 for e in equity: if e > peak: peak = e dd = (peak - e) / peak * 100.0 if dd > max_dd: max_dd = dd print("Managing risk and drawdown") print("Account peak: $100000") print("Trough: $70000") print("Max drawdown: %.1f%%" % max_dd)

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Managing risk and drawdown Account peak: $100000 Trough: $70000 Max drawdown: 36.4%
A 50% drop means you must double the rest just to break even. Drawdown is the number that decides whether you get another chance at all.
2

I risk a fixed small fraction of the account and size the position so that losing the stop makes the trade affordable rather than catastrophic.

account = 100000.0 risk_per_trade = account * 0.01 entry = 100.0 stop = 95.0 shares = risk_per_trade / (entry - stop) print("Risk per trade (1%%): $%.2f" % risk_per_trade) print("Shares sized: %d" % shares)

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Risk per trade (1%): $1000.00 Shares sized: 200
Risk 1% and a losing streak just gets you smaller. Risk 20% and a bad month ends the story for good.

Put it in order

Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.

Data Flow

Drawdown is measured, then controlled with position sizing and diversification so a bad streak can't end the run.
1 Measure drawdown
↓
2 Size each position
↓
3 Spread across strategies
↓
4 Set a max loss limit
Line by line

Read the first example one line at a time. A line that prints shows what appears on screen; the rest set things up quietly.

equity = [100000, 102000, 99000, 110000, 105000, 70000] sets nothing on screen
peak = equity[0] sets nothing on screen
max_dd = 0.0 sets nothing on screen
for e in equity: sets nothing on screen
if e > peak: sets nothing on screen
peak = e sets nothing on screen
dd = (peak - e) / peak * 100.0 sets nothing on screen
if dd > max_dd: sets nothing on screen
max_dd = dd sets nothing on screen
print("Managing risk and drawdown") Managing risk and drawdown
print("Account peak: $100000") Account peak: $100000
print("Trough: $70000") Trough: $70000
print("Max drawdown: %.1f%%" % max_dd) Max drawdown: 36.4%
Why this works
Position sizing

Risk a small, fixed fraction of the account per trade. One percent makes a losing streak survivable; twenty percent can end it on Tuesday. Sizing is the single most important decision a trader makes, and it's almost never the exciting part.

Diversify properly

Spread money across strategies that move independently, so one loss is cushioned by another win. If it seems calm and diversified but everything still falls together, the calm is an illusion.

Examples

How bad it can actually get

Account peak: $100,000
Then it fell to $70,000
Drawdown = 30%

A 30% drop is survivable. A 50% drop means you need to double the rest of your account just to get back to zero. Drawdown isn't theoretical, it's the number that decides whether you get another chance at all. Chasing returns is the fun part; keeping drawdown small is the part that lets you keep playing.

Risking a fixed fraction

risk_per_trade = account * 0.01
shares = risk_per_trade / (entry - stop)

Risking 1% of the account per trade means a long losing streak just gets you smaller, not wiped out. Size it that way and a bad month is uncomfortable. Risk 20% and a bad month is the end of the story.

The diversification that isn't

Holding 5 tech stocks
Feels like diversification
Actually one bet

If every position falls together, you haven't diversified, you've made five versions of the same bet. Real spread means the positions move independently, so when one drops the others don't all fall at once. Most people diversify the name but not the risk.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Backtesting strategies on history
Previous Lesson
Backtesting strategies on history
Next Lesson
Simple models and predictions
Simple models and predictions →