Summary
- Backtesting is the process of testing trading theories on historical data.
- With customized backtesting methods, investors can even provide inputs for margin needs, slippage assumptions, interest rates, and stop orders to tune their settings to match the real-world as closely as possible.
- Backtesting can be automated. This is done by gauging performance against parameters like its dollar P/L, the Sharpe ratio, success ratio, and more.
A trading strategy is a scheme designed to produce profits through the transfer of assets on an exchange. Trading strategies comprise many elements, and there are countless strategies accessible to anyone on the internet. Some popular trading strategies have been vetted through years of widespread use, but others are used at the risk of your assets.
Trading strategies are fundamentally grounded in logic, but this logic isn’t always perfect. A successful system in one market can quickly become unusable in others. While countless people are willing to sell you the ‘top-secret maximum profits strategy,’ you’re never guaranteed a flawless approach.
What is Backtesting?
Backtesting is one of the most critical tools in a trader’s utility belt. It allows investors to see a strategy’s performance against an asset’s past price movements and decide which methods to employ based on that information. It represents a similar concept to ideally not buying anything from a non-reputed brand.
In essence, backtesting is the process of testing trading theories on historical data. Instead of applying vague strategies on current data and risking real capital, backtesting lets the trader tailor their approach for each investment.
Backtesting is a fundamental part of developing any trading system, and if correctly implemented, it can aid speculators in optimizing and improving their trades. It also allows investors to look for theoretical flaws and gain more confidence in their strategic decisions before applying them in a real-world scenario.
Backtesting in Different Markets
However, backtesting isn’t foolproof and requires some broader context of the market you’re trading in. For instance, if you tested a strategy on the 90s dotcom bubble, it may have performed brilliantly during the market’s prime but would have likely failed after the bubble burst. The phrase, ‘past performance is not indicative of future returns’ rings heavy here, but that hasn’t stopped people from practicing backtesting techniques to optimize their trading activities.
Before backtesting a strategy, make sure to account for broad market trends in that time frame, both when analyzing the historical data and when applying the strategy in current markets. With customized backtesting methods, investors can even provide inputs for margin needs, slippage assumptions, interest rates, and stop orders to tune their settings to match the real-world as closely as possible.
Unfortunately, this can also lead to ‘over-optimization,’ a situation where performance metrics are tuned too precisely for historical data and become inaccurate enough for real-world trades.
Using Software and Statistics
Backtesting involves defining a trading strategy’s rules, usually through software, for use with market data from a specified period. Statistics are then extracted from the results to gauge how effective the strategy could be in real markets. This belief is driven by the theory that past successful strategies are likely to work well in the future. While it isn’t the case every time, it does give traders a decent idea of what to expect from their investment methods.
Can You Backtest Crypto Trading Strategy?
Blockchain is a young solution to an age-old problem, but though the industry is small, it’s benefits are far-reaching. Currently, however, low liquidity levels plague many smaller exchanges, so it’s vital to tune your backtesting software to account for issues like latency and slippage based on the crypto exchange you want to use.
Without simulating other traders’ antics on an exchange, backtested strategies can face some curveballs when used in practice. One of the rookie mistakes that traders run into is implementing historical data strategies that require future information. For example, you cannot backtest a strategy that buys assets at their 24-hour low because the market wouldn’t have that information until later.
Backtesting is a nuanced subject, and most experienced traders recommend building backtests from scratch. Each strategy is different, and the differences between them aren’t always noticeable. Structuring your backtest to best adhere to a trading strategy will minimize the chances of failure. It’s also critical to consider factors like risk-exposure levels, profit targets, and investment frequency before conducting tests.
Automated Backtesting
Just as trading can be automated, so can backtesting. Traders write and compile code to automatically place trades according to their specified strategies, but it’s necessary to keep the code updated to match current market conditions.
Before choosing a platform to test out a strategy, you need to consider whether your chosen investments are supported and learn how it sources market data. You’ll also need to decide which programming language you’d like to use and how you’ll implement your chosen trading strategy in code.
Traders also generally evaluate their systems using benchmark parameters before fully implementing backtesting measures. This is done by gauging performance against parameters like its dollar P/L, the Sharpe ratio, success ratio, and more.
Dollar Profit and Loss (P/L)
Total P/L or Total Profit and Loss help traders determine whether a trading strategy was profitable or not, and how much profit or loss could potentially be incurred using that strategy in similar situations. As the name suggests, the Average P/L denotes the average profit or loss that could occur over an interval of time, usually minutes, hours, or days.
The Success Ratio
The success ratio is the ratio of the number of individual trades that reported profits against the number of transactions that took losses. This can be a significant indicator of a successful trading strategy and how much it needs to be updated or optimized to reel in the most profits.
The Sharpe Ratio
The Sharpe ratio measures the risk-adjusted return of two strategies that offer similar returns at different risk levels. Risk can be measured using maximum drawdown, which denotes the maximum drop in value from the asset’s peak price. This helps investors evaluate the overall risk involved and the potential losses that could be incurred.
Programming Languages (C++, C#, Java, MATLAB, R, and Python)
Programming language can play an influential role in developing a backtesting platform, and it’s crucial to weigh out the pros and cons of each language based on your backtesting needs. Some of the most commonly used programming languages are C++, C#, Java, MATLAB, R, and Python.
C++ offers the best execution speed and has the most flexible memory management modules to optimize it. However, this can lead to some bugs during operation, and the language is known to be challenging to learn.
C# and Java perform automatic ‘Garbage Collection’, which has higher performance overheads but allows for more rapid development. Both have native GUI capabilities, libraries for numerical analysis, and fast execution.
For more scientific calculations, MATLAB offers a commercial IDE that’s compatible with numerical libraries for scientific computation. While its execution speed is undoubtedly formidable, it’s probably too costly for retail trades.
R has a dedicated open-source statistics scripting environment that is cross-platform and offers several free packages for advanced analysis. However, unless operations are vectorized, R’s execution speed is somewhat lacking.
Speaking of open-source, cross-platform programming languages, Python has a rich repository of packages for all kinds of tasks. It is a high-level object-oriented programming language that offers user-friendly data structures. It even has a specialized research environment, and its execution speed is adequate for intra-day trading.
Simulated Trading
Using a simulator can provide further insights into some of the problems that occur during a strategy’s execution. Simulators behave like exchanges and can be configured to match different market conditions, but their implementation in languages like Python, Java, and C++ may require greater proficiency with the languages.
Interested in Simulated Trading?
Try Phemex Testnet and Trade with Zero-Risks
Backtesting Strategies for Bitcoin
There are two main kinds of backtesting: research backtesting and event-driven backtesting.
Research Backtesting
Instead of fully simulating all aspects of a market, research backtesting tools make approximations to relay performance information faster. While research tools are often used within the professional quantitative trading industry to get a first impression of a new strategy, they aren’t quite suitable for the frequency of intra-day trading.
Event-Driven Backtesting
Event-driven backtesting tools connect to real-time market feeds, triggering trades when any coded market events occur. Event-driven systems run perpetually and often have subsystems to handle historical data and simulate brokerage to create a more realistic execution. However, their design is rather complicated and far more prone to bugs.
Market prices are vulnerable to a myriad of factors, and their fluctuations can often be traced back to the events taking place during that time. This includes significant announcements, the introduction of new monetary policies, inflation rates, the publishing of annual reports, and more. It’s important to note here that the market won’t behave similarly every time, making it crucial to test trading strategies in differing market conditions.
Markets will be markets
Backtesting is a principal part of selecting a trading strategy, but even expert backtesters can fall prey to certain biases that significantly alter findings.
Of these biases, one of the most common is the optimization bias. This is when a backtesting strategy is so perfectly optimized for historical data that it can no longer perform optimally in real-world markets. As mentioned earlier, there can also be biases that create the need for future data in historical data backtesting.
This is known as look-ahead bias, and even a small oversight like miscalculating the publishing of an annual report can skew results. Bias can creep up on even the most experienced trader, so it’s imperative to remain vigilant throughout the backtesting process.
As cryptocurrency trading gains more popularity, backtesting, too, has become widely adopted by investors and traders in the space. With markets as wild and unpredictable as cryptocurrencies, it can be beneficial to backtest trading strategies before attempting to apply them in the market.
Backtesting also lets traders analyze the results to see how to improve their strategies. Systems optimized for trending markets may not work as expected in ranging markets, and the analysis of results from backtesting can help customize your settings to maximize gains.
However, external market events can still throw a spanner in the works of your strategy. Backtesting a strategy doesn’t guarantee profits, but through testing against a large amount of historical data, traders can get a clearer idea of how well it could function in current markets.