What is Backtesting? 3 Aims of Backtesting

2 min read

Get 10-day Free Algo Trading Course

Last Updated on May 12, 2021

Performance report from backtrader backtester
Backtesting Guide

What is backtesting? Backtesting is the process of testing a trading or investment strategy using data from the past to see how it would have performed.

Understanding backtesting

Running a backtest

The general idea of a backtest is to run through stock prices in the past, usually with software, and hypothetically firing trades based on a certain trading strategy.

For example, let’s say your trading strategy is to buy Amazon when it falls 3% in a day, your backtest software will check Amazon’s prices in the past and fire a trade when it fell 3% in a day.

The backtest results will show if the trades were profitable.

Backtesting can be as simple as running analysis in Excel to something more complex such as creating custom backtesting software. It all comes down to your individual requirements.

The 3 Aims of Backtesting

Backtesting accomplishes 3 things:

  1. Shows if a strategy performs well in periods when it is supposed to, and vice versa
  2. Provides an understanding of how the strategy performs in different markets.
  3. Produces insights on how the strategy might be improved on.

1. Performance during selected periods

With a backtest, we can check to see if a strategy makes money when it is supposed to and loses money when it is supposed to.

For instance, let’s say that our strategy is expected to perform better when the markets are volatile, or in other words, when they move much more than they normally do.

If our backtests then show that we make more money than expected during less volatile periods, this is a red flag (even though we made money).

We need to examine our strategy and figure out why.

2. Understand how the strategy performs in different markets

To gain more confidence over how consistently a trading strategy will perform, backtests can be run in different market environments.

This means running backtests with different stocks or other market assets.

It could also mean performing tests during periods where there are clear trends and comparing them to periods where there weren’t.

3. Improving the strategy

This involves making changes to a strategy after looking through the results of the backtest.

A common pitfall here is to continuously tweak the strategy so that it shows better results in a backtest.

This approach rarely leads to profitability when you trade it with real money and is known as overfitting.

Why is backtesting important to you?

Backtesting is an essential part of developing a trading strategy.

Pass, improve, or fail

A backtest can help decide if a strategy is suitable to trade real money, can use improvement, or if it’s best to give up on it.

Deploying a strategy

As mentioned, backtesting helps us understand how our strategy performs in different market environments, this will allow us to deploy our strategy better.

A trader might have multiple strategies. By knowing the strength and weaknesses of each of the strategies, it will be clear when is it best to deploy a certain strategy.

Certain strategies pair well with others. Some strategies don’t work well when market conditions are unfavorable. Running backtests will provide the information needed to decide when to deploy which.

What are some Backtesting Tools?

There are several tools available to help you conduct a backtest. 

A common way is to use a trading platform.

Trading platforms

Popular trading platforms that include backtesting capabilities include QuantConnect, MetaTrader 4 & 5, Tradingview, ThinkorSwim, and Ninjatrader.

The benefit of using such a platform is that most of them include the necessary data. Several of them also have built-in analysis.

Performance summary of a backtest in Tradingview

Coding libraries

As an alternative to using a solution tied to a trading platform, there are several coding libraries that can help in backtesting.

For those familiar with Python, Backtrader and Zipline are both great options.


Here is our complete guide to Backtrader (Python):
Backtrader for Backtesting (Python) – A Complete Guide


These libraries can accommodate a lot of customization. The trade-off is that the learning curve is a bit steeper.

Returns chart created in PyFolio

Analysis tools usually come with backtesting software. There are also third-party solutions available such as Pyfolio. This Python library simplifies creating charts and calculating statistics.

Backtesting software is not a necessity. The above image shows a chart that tests a hypothesis that gold prices rally for a few days after a Fed meeting

All it took was a simple charting library and some historical data.

What are the 3 Backtesting Mistakes?

It is easy to misuse backtests to develop a flawed strategy that looks good historically but fail in live trading.

Here are 3 common mistakes to be wary of:

  • Overfitting
  • Look-ahead Bias
  • P-hacking

Do check out this lecture PDF to learn more: 3 Big Mistakes of Backtesting – 1) Overfitting 2) Look-Ahead Bias 3) P-Hacking

Jignesh Davda