What Is Backtesting
Backtesting is a set of technical rules applied to historical price data, followed by an analysis of the profits that a particular strategy could generate over time. Traders can use backtesting to understand whether or not their chosen strategies can provide sustainable results.
This blog will help you understand backtesting and why it’s important for trading. It will also look at ways you can backtest your trading strategy.
- Backtesting helps traders and investors understand how their strategies would have fared in different market conditions.
- Traders can backtest strategies manually or automatically. Manual backtesting requires no coding background, but it can be time-consuming and inaccurate. Automated backtesting requires coding knowledge, but it’s more efficient overall.
- Backtesting is essential for structured and complex DeFi products.
- DeCommas pays lots of attention to backtesting, ensuring a secure and automated DeFi experience for the end-users.
Introduction to Backtesting
Imagine you have noticed an indicator that has been giving good signals for 2 days in a row (it was 2 days ago that you learned about it). The performance is slightly negative on the third day, but you continue anyway. The next day is neutral. You feel confused, but your trust in strategy still holds true.
What happened, you wonder, scratching your head thoughtfully. I’ve set parameters correctly, haven’t I? You adjust parameters just in case, play with the data scale, and trade instruments. Such behavior will likely result in losses, and the reason is quite simple.
Several days of positive performance are not enough to be sure that a particular method brings sustainable profits. To ensure the strategy is reliable, you need data. The more — the better. Backtesting is how you obtain the data without risking your money.
What is Strategy Backtesting?
Silicon Valley startups have a useful habit: testing hundreds of different hypotheses (sometimes completely wild), and seeking effective patterns for their products. Such an approach is part of the business optimization agenda. It helps to test hundreds or thousands of ideas based on qualitative and quantitative research.
Backtesting is the same technique applied to trading.You take a hypothesis (a trading strategy that you want to run with real money) and put it through quantitative research (testing the strategy on historical quotes with different settings). Even though you may not initially have hundreds of trading strategy ideas, a couple will be enough to get you started.
Why Does Backtesting Matter?
Testing trading strategies is just like training before a competition or crash-testing a car before its official release. Without these sequential activities, winning the competition or producing a decent car that will sell in the market is impossible.
Financial markets may force traders and investors to act irrationally mainly because traders use heuristic shortcuts and stereotypes to navigate uncertain markets and make sense of the surroundings at a decent pace.
Trading at random is one example of irrational behavior. Such behavior usually triggers traders to use strategies that have not undergone any prior testing. The chances of making systematic profits with untested strategies tend to zero. Backtesting is a way to minimize irrational behavior, resulting in sustainable profits.
What Backtesting Methodologies Exist?
Backtesting is a type of testing that relies on historical data to predict future performance. This data is used to generate a market model, which is then used to test the strategy.
There are several different types of backtesting methodologies that can be used in trading automation, including but not limited to the following.
Monte Carlo Simulation
Monte Carlo simulations use a large number of randomly generated data points, which are then used to evaluate hypothetical scenarios for a trading strategy. Such simulations are often used to test trading strategies that involve a large number of variables.
Alt: monte carlo simulation crypto
Learn more about Monte Carlo simulations
Traders specify two types of sample testing: in-sample and out-of-sample testing.
The in-sample forecast is the process of formally evaluating the predictive capabilities of the models developed using observed data to see how effective the algorithms are in reproducing data.
Suppose you have a sequence of 5 data points. You can divide the data into two parts in relation to the model: estimation and performance. Say you allocate 3 data points for estimating the model and 2 more data points to test the performance.
- The prediction made for the first 3 data points is the in-sample forecast.
- The prediction made for the last 2 data points is the out-of-sample forecast.
This is the same as splitting the data into training and validation sets.
Alt: out-of-sample testing
Find out more about sample testing.
The Robustness testing technique helps to assess the sensitivity of a trading strategy via assumptions or parameter values. Traders and analysts use robustness testing to understand how the strategy would perform under slightly changed inputs, historical data, and other trading parameters.
Walk-forward backtesting involves testing a trading strategy on a rolling basis, using data from a specific time period to generate signals, and then moving forward in time to see how the strategy would have performed on subsequent data. This method is often used to test complex strategies, as it allows for a more realistic assessment of how the strategy would have performed.
Alt: walk-forward testing
Broaden your knowledge about walk-forward optimization.
The choice of backtesting methodology will depend on the specific goals and constraints of the trading strategy, as well as the availability and quality of the data.
How To Backtest DeFi Strategies?
You can either backtest your DeFi strategies manually or automatically.
- Manual backtesting is simpler, requires no coding background, and generally yields less accurate results
- Automated backtesting is complex, requires coding background knowledge, and yields more accurate results if performed meticulously.
Regardless of your backtesting approach, you need to stick to the following steps.
- Define the rules of the trading strategy, including any entry and exit criteria, position sizing, and risk management rules.
- Collect historical data for the instruments you want to trade, including price, volume, and any other relevant indicators.
- Use the historical data to simulate the trades that would have been generated by the trading strategy, using the defined rules.
- Record the results of the simulated trades, including the entry and exit prices, the profit or loss for each trade, and any relevant performance metrics.
- Evaluate the performance of the trading strategy using various statistical measures, such as the Sharpe ratio, the maximum drawdown, and the win/loss ratio.
- Make any necessary adjustments to the trading strategy based on the results of the backtesting, and repeat the process until you are satisfied with the performance of the strategy.
Let’s talk a bit more about manual and automated backtesting.
Manual DeFi Strategy Backtesting
If you know little to no about coding, manual backtesting is a way to go. At bench scale, you can manually collect specific information and use spreadsheets to process it. The information required may vary depending on your DeFi activity and the way you approach markets. For example, intraday traders might be interested in collecting statistical information like potential gaps in opening/closing prices.
Let’s assume you seek arbitrage opportunities between DEX & CEX. Here’s the trading information you’re going to need:
- Date and time of your transactions
- Long or short positions
- Entry and exit prices
- Profit and loss including commission and slippage
- Cumulative profit
Once you have data journaled, use software like Excel to put all the data in a table. This way, you’ll be able to analyze the data to see how your strategies perform. If you’re not sure how to analyze the collected data, use 3 approaches to backtest your data digest for inspiration.
Automated DeFi Strategy Backtesting
You can automate backtesting to analyze more data quicker and get more accurate results. Such an approach requires a coding background (C++, Matlab, R) and access to high-end databases like EOD Historical Data. For more info, check out the comprehensive list of tools you might need for automated backtesting. The specifics mainly depend on your programming language pick and backtesting approach, though.
Python is one of the most accessible ways to perform backtesting, which is why most retail traders prefer it over other programming languages. You can learn more about Python backtesting in a YouTube crash course or in a detailed take on backtesting with Python.
Here’s an example of automated backtesting code for Uniswap V3 LP Strategy.
Automated backtesting is mainly used by either institutions or advanced traders. The main areas of automated backtesting applications are arbitrage strategies, hedging with derivatives, and liquidity providing strategies.
How Backtesting Applies to DeCommas?
DeCommas is a DeFi automation layer, meaning we seek to provide users with
- Easy access
- Automated on-chain strategies
- Sustainable yields
As such, structured DeFi products and arbitrage strategies become our primary focus. Backtesting develops into an absolute necessity due to the infancy of structured products and arbitrage strategies within the DeFi niche.
The DeCommas team performs both in-house backtesting and outsourcing to ensure a sustainable and automated DeFi experience for the end users. Backtesting ensures data filtering, modeling, optimization, and identification. Including the following.
- Objectively evaluate trading idea or hypothesis, without emotion or bias
- Identify the statistical value of DeFi trading strategies
- Optimize and improve the DeFi strategies
- Spot the strengths and weaknesses of DeFi strategies.
DeCommas analyzes cluster periods over the data set. Applying the portfolio model over smaller periods generates portfolio returns and weights for the chosen intervals. The backtesting periods and intervals are referred to as rolling windows because of the periodized test process.
The portfolio’s return that reflects the backtesting intervals is then calculated by multiplying the asset weights by the return of each asset. The cumulative returns are then calculated for the entire DeFi portfolio and each strategy and compared with results obtained from the DeFi portfolio model.
Keen to discover more? Find out what are delta-neutral strategies, and projected yields.
Backtesting is essential to boost your performance across niches, including DeFi activities like liquidity providing, DEX arbitrage, and more. The DeCommas in-house team uses powerful backtesting techniques to ensure you don’t have to worry about collecting data or running tests, thus automating your DeFi experience.
Transparent performance data also ensures you may feel more comfortable allocating your assets to specific strategies we provide access for.