Whether you’re day trading, swing trading, or following any other trading strategy in financial markets, the fast-paced concept of buying and selling positions in the market is exciting and can make you plenty of money.
It can also lead to losses. No matter what asset you trade, from stocks to cryptocurrency to forex trading, there’s always volatility and the risk of loss.
Backtesting is one of the best ways to manage risk by showing you whether a trading strategy you’re interested in employing has a high probability of generating profits.
What Is Backtesting in Trading?
Backtesting is a tool traders use to determine if the trading strategy they’re considering has any real viability based on historical data. In the simplest terms, backtesting is the process of using historical market data to see how your trading strategy would have performed in the past.
You own shares of Apple, Amazon, Tesla. Why not Banksy or Andy Warhol? Their works’ value doesn’t rise and fall with the stock market. And they’re a lot cooler than Jeff Bezos.
Get Priority Access
Backtesters set trading rules using lines of custom code or pre-built software. Once all the trading rules of your strategy are in place, the program tests those rules in a live trading environment throughout a predetermined period of time.
If the results of the backtest are positive, it’s a good sign your trading strategy will be a profitable one.
However, some experts suggest you should combine backtesting with a paper trading account before employing your strategy in the real world. Past performance isn’t always indicative of future results.
Moreover, unless you use your strategy as an algorithmic trading strategy, there’s potential for human error. Trading simulators let you test your strategy in real-time using a life-like trading platform the same way you would trade in the real world.
It may be best to use backtesting as a viability test and use a trading simulator to confirm the backtester’s results.
How Backtesting Works
As recently as a decade or so ago, you would have to be a programmer with knowledge of Python or other scripting languages to backtest your trading strategy. Today, there are several backtesting programs available, some of which are free and some you’ll have to pay for.
These programs let you set specific trading parameters based on technical indicators. The programs generally work on“if/then” triggers based on certain metrics.
For example, your strategy might entail buying a stock when its 10-day moving average crosses above the 45-day moving average. Backtesting programs use historical datasets from real-world market data to test specific “if/then” sequences just like this.
You’ll need to input the following data when you use a backtester:
- Assets. You need to let the program know the types of assets you’re interested in trading. For example, are you trading stocks, currency pairs, or other types of assets?
- Entry Rules. Entry rules are a series of “if this/then that” rules that stipulate when a trade should be entered.
- Exit Rules. Exit rules are another series of “if this/then that” rules that stipulate when a trade should be closed. In particular, exit rules set profit and stop-loss boundaries.
- Portfolio Starting Size. This is the amount of working capital you have in your portfolio at the beginning of the test.
- Trading Costs. Transaction fees you pay cut into your profitability, so you should account for them in your backtesting.
- Time Frame. This is the testing time period. For example, you may want to see how the strategy would have performed over the last 60 days.
Once you fill out the data, the tester gets to work. These programs comb through a significant amount of data, so it may take a few minutes to get your results.
Each program provides its own set of data, but the vast majority include at least the following in the results:
- Profit or Loss. The results tell you how much money you would have gained or lost during the test’s time frame using your strategy. Most testers offer both return on equity and annualized return data.
- Maximum Drawdown. The maximum drawdown is the highest amount of losses the portfolio experienced at one point in time through the test. For example, a test that has a maximum drawdown of 3% means that at the worst-performing point in the testing period, the trading strategy was down 3%.
- Risk Statistics. Traders use a wide range of metrics to measure market risk. Two of the most common include the Sharpe ratio and the win/lose ratio. Some testers also provide data like the most consecutive winners, most consecutive losers, biggest winners, and biggest losers.
If the test results are positive and you’re happy with your trading or investment strategy’s performance, you may be ready to move to real-world trading. Make a few trades on a trading simulator to verify how you’ll do in the live market, and you’re ready to hit the big leagues.
If the test results are negative, it’s time to make a change. Tweak the parameters of your trading strategy and run the test again. Continue to do so until the strategy produces positive results.
Why Backtesting Is Important
Financial markets are volatile, and volatility doesn’t come with directional favoritism. Trading is the process of exploiting this volatility in an attempt to generate profits — a very high-risk endeavor.
When you trade, you realize strategies that seemed perfectly simple aren’t. Others that perform well under some market conditions don’t perform well in others. The human mind may be powerful, but it’s not perfect, so you can’t always trust your trading ideas to perform well.
Instead, it’s best to rely on real market data when determining whether a new strategy — or changes to an old one — will be effective in the real world.
Of course, backtesting programs rely on historical data, and historical performance isn’t always indicative of what you can expect in the future. So why not just use a trading simulator?
Testing a strategy using a trading simulator in real time can take days or even weeks to gather enough data. Moreover, if you want to see how the strategy will do under varying market conditions, you may have to test the strategy for months. If the test fails, it’s back to the drawing board and more time is wasted.
Backtesting does most of the work for you, testing your strategy over a period of time that’s long enough to encapsulate varying market conditions and trading scenarios. And these programs do it all in a matter of minutes.
Sure, it’s best to test your strategy using a paper trading account to account for human error and verify backtesting results, but using a backtester shaves quite a bit of time from the process of testing and perfecting your strategy.
How to Backtest Your Trading Strategy
If you’re sold and you’re ready to put your trading strategy into a backtester to see how it performs, great. Follow the steps below to get started.
Choose a Backtesting Provider
There are several backtesting programs available online. Some are free and some are part of a monthly subscription service that generally includes several trading tools.
Do a little research and compare a few different options. As you compare, consider:
- The Price. Your trading tools shouldn’t be so expensive that they make it nearly impossible to turn a profit. Always consider the price you pay for tools and the overall value they provide.
- Customization. Some programs have pre-built strategies for you to backtest. They may allow you to customize the parameters of their own strategies, but that’s about as far as their customization goes. Others allow you to build your own strategies from the ground up, with every factor completely customized. If you’re new to trading, the pre-built options might be appealing, but if you have experience, you’re better suited with a highly customizable option.
- Data Provided. The data provided in the results of the test is the point of value for these programs. Some only provide limited information on your profit or loss, max drawdown, and other basic factors. Other programs go deep into the data, offering detailed insights that help you determine where to tweak your strategy if the test proves ineffective.
- Artificial Intelligence. Some backtesting services couple traditional backtests with artificial intelligence to guide you through perfecting your strategy. These programs tell you where small changes make the biggest impact and often guide you through the process of making those changes.
Once you pin down a provider, sign up for the service and move on to step #2.
Step #2: Set Up & Run Your First Test
Most backtesting programs available today are designed for simplicity, but each program is different from the next. Follow the instructions in the program you chose to set up and run your first test, filling out parameters like entries, exits, stop-losses, assets traded, and the period of time you want to test.
When you set up your test, it’s important to choose your time frame wisely. Longer time frames are more intensive and take longer to run, but it’s worth the wait. It’s best to make sure the time period you choose is long enough to cover multiple market conditions and trading circumstances.
Step #3: Analyze the Results
The first thing you want to know when you run a backtest is whether the strategy proved to be profitable.
Next, look at the maximum drawdown and other risk metrics to determine whether you can change anything to decrease the risk the strategy exposes you to while maintaining or improving returns.
Step #4: Tweak Your Strategy
Based on the backtesting results, make small changes to your strategy and run the test again. This helps you determine if there are any improvements you can make. If you use a platform guided by artificial intelligence, follow the steps provided and see how the program’s recommendations work out in the real world.
Step #5: Do Some Real-Time Testing
Once you’ve pinned down a solid strategy using a backtester, launch a trading simulator and confirm the results in a real-time trading environment. If all goes well, you’re ready to move on to real trading with real money.
Tips for Backtesting Trading Strategies
You want to make the most of the data you generate when backtesting your trading strategies. Follow these tips to do so:
- Always Confirm Results. Backtesters use past performance to predict the potential future performance of a strategy. The past isn’t always indicative of what’s going to happen in the future. You should always use a trading simulator to confirm the results of a backtest in today’s marketplace.
- Software Makes the Difference. There are several trading software options that offer backtesting capabilities. However, they’re not all created equal. Be sure to choose a program that provides comprehensive data; AI-assisted options are a plus.
- Make Sure You Have a Large Enough Sample Size. Some strategies perform well in all market conditions, while others only perform well under certain conditions. Make sure you backtest with a time period that’s long enough to include multiple market conditions and trading circumstances.
- Pay Close Attention to Risk Metrics. No matter how great the test results are in terms of returns, it’s important to minimize your risk. Pay close attention to the Sharpe ratio, maximum drawdown, and win/loss ratio when analyzing your results to make sure you’re not accepting too much risk as you trade.
Backtesting has evolved quite a bit and has become a simpler option for the average investor. However, that doesn’t mean you won’t have questions. The answers to some of the most common are below.
What’s the Best Backtesting Software?
There’s no one-size-fits-all financial product. That’s true whether you’re talking about an exchange-traded fund, a bank account, or financial software.
However, there are some options that have proven to be better than others. Some of the best backtesting software options include TD Ameritrade’s thinkorswim trading platform, MetaTrader 4, and Edgewonk.
How Many Trades Do You Need to Backtest?
Your margin for error shrinks as your trading sample grows. You should backtest at least 200 trades, but some traders are more comfortable backtesting 500 or 600 trades. Backtesting more trades gives you an adequate sample size to tell whether the results of the strategy were consistent or just a fluke.
What Time Period Should You Backtest?
As is the case with the number of trades, the margin for error shrinks as the testing time period expands. You should look at minimum time frames of around 60 days, but don’t be reluctant to run a 180-day test to build more reliable data.
As technological innovation continues, we have access to more and more tools to improve our trading. Backtesting is one of the most powerful tools online today.
These programs analyze mountains of data and determine if your strategy would have performed well over a predetermined period of time. Although history isn’t always going to repeat itself, backtests have proven invaluable in validating new trading ideas.