A vectorised backtest calculates a strategy's signals and returns on entire columns of historical data at once, using array operations, which makes it very fast but less realistic about order execution.
In short
- Very fast; ideal for exploring many ideas and settings.
- Works well for simple daily strategies.
- Easy to introduce look-ahead bias by misaligning data.
- Approximates fills, costs and position sizing.
How it works
Instead of looping through time, a vectorised backtest uses array calculations, for example with Python's pandas or NumPy. It computes an indicator for all dates at once, converts it into a position series (such as 1 for long, 0 for flat), shifts that series forward one period so trades happen after signals, and multiplies by the asset's returns to get strategy returns.
This approach can test years of data in a fraction of a second, so researchers can try thousands of parameter combinations, many assets or many variations quickly. Libraries such as vectorbt are built around this idea.
The most common error is forgetting to shift signals. If a position based on today's close is applied to today's return, the backtest uses information it could not have had, producing unrealistically good results. Careful alignment of data is essential.
Vectorised tests also simplify execution. They usually assume trades fill at the close or next open at a known price, apply costs as a fixed percentage, and struggle with limit orders, stop orders within bars, path-dependent position sizing and portfolios with shared capital limits.
Because speed makes it easy to test very many variations, vectorised research carries a high risk of over-fitting. Promising results are usually checked out of sample and then in a more realistic event-driven backtester before trading.
An example with numbers
A researcher computes a 50/200-day moving average signal for 20 years of index data in one line, shifts it by a day, multiplies by daily returns and subtracts 0.05% per position change. The whole test runs in milliseconds.
How it differs by market
| Market | What to know |
|---|---|
| Global | Vectorised testing in Python is a common first step in quantitative research. |
Where people go wrong
- Not shifting signals, which creates look-ahead bias.
- Trusting results from thousands of tested variations without out-of-sample checks.
Common questions
What is a vectorised backtest?
A test that calculates signals and returns on whole data arrays at once.
Why use it?
Speed: it can test many ideas and settings very quickly.
What is the most common mistake?
Applying a signal to the same period's return, which uses future information.
What does it handle poorly?
Limit orders, intrabar stops, path-dependent sizing and shared capital.