Quant for Free
Home / Learn / Your first backtest
Learn · Module 4

Your first backtest

Every strategy, from a hobbyist's to a hedge fund's, is the same four parts: a signal, an entry, an exit, and a size. We'll snap them together into the classic beginner strategy — a moving-average crossover — and watch it run.

What you'll learn
  • The four parts of any strategy: signal, entry, exit, size
  • A worked moving-average crossover, step by step
  • Why position sizing matters as much as the signal
  • Vectorized vs. event-driven backtests, in plain terms
Module 4 of 8 · ~9 min read · uses Modules 1–2

Every strategy is four parts

Strip away the jargon and a trading strategy answers four questions, in order:

PART 1

Signal

What condition am I watching for?

PART 2

Entry

When the signal fires, how do I get in?

PART 3

Exit

What makes me get out — win or lose?

PART 4

Size

How much do I put on this trade?

Miss any one and you don't have a strategy yet. Beginners obsess over the signal and forget the other three — but as you'll see, exit and size decide your fate at least as much as the entry does.

A worked example: the moving-average crossover

The "hello world" of backtests. A moving average (MA) is just the average price over the last N days, recomputed each day — it smooths the noise so you can see the trend. We use two: a fast one (say 10 days) that reacts quickly, and a slow one (say 50 days) that moves ponderously.

BUY SELL BUY fast MA (10d) slow MA (50d) price
Buy when the fast MA crosses above the slow; sell when it crosses back below. The whole strategy, in one picture.

Run that rule over years of history, tally the trades, and you have a backtest. Feed the trade results into Module 2's scoreboard — CAGR, Sharpe, drawdown — and you can finally answer "would this have worked?"

Size is not an afterthought

Two traders run the identical crossover signal. One risks 2% of the account per trade; the other risks 30%. Same entries, same exits — wildly different fates. The reckless one can be wiped out by a normal losing streak the careful one shrugs off. Position sizing turns a signal into a survivable strategy, and it's the difference between a backtest that compounds and one that goes to zero on trade 14.

This is its own discipline, and we built a calculator for it: the Position Size & Risk of Ruin tool runs a Monte Carlo of your edge to show how sizing changes your odds of survival. Module 6 goes deep on it.

Vectorized vs. event-driven

Two ways to actually compute a backtest, and it's worth knowing the words:

Before you get excited. The crossover is a teaching tool, not an edge. Run honestly — with real costs and on data it hasn't seen — this simple version usually breaks even or loses. That's not a bug in your code; it's the lesson. A backtest that "works" on the first try almost always has a flaw hiding in it, which is exactly what Module 5 teaches you to find.

Key terms from this module
Signal
The condition a strategy watches for.
Moving average
The average price over the last N periods, recomputed each step.
Backtest
Running a strategy's rules over historical data to tally how it would have done.
Position sizing
How much capital to commit per trade — the survival dial.
Vectorized / event-driven
Computing all signals at once vs. stepping bar-by-bar like live trading.

Where to go next

You can build a backtest now — which means you can also fool yourself with one. Module 5 is the most important in this course: the validation gauntlet that separates a real edge from a lucky-looking curve.

Size your first strategy properly

Tool
Position Size & Risk of Ruin — see how 2% vs 30% per trade changes your odds of survival
Educational content, not investment advice. This lesson explains concepts and methods only. The moving-average example is a teaching illustration, not a recommendation to trade. Nothing here recommends any security, strategy, or trade, or promises any outcome. Trading involves risk of loss. See the disclaimer.