In our previous article, “Algorithmic Trading on Aspis Protocol”, we introduced the fundamental concepts of algorithmic trading on the Aspis Protocol and how users can leverage the platform to deploy sophisticated trading strategies. Today, we are excited to take this a step further by introducing advanced backtesting tools that empower traders to not only launch their algorithmic trading strategies but also continuously refine them for better performance. With these tools, you can adjust strategy coefficients, test them against historical data, and simulate real market conditions for optimal results.
To get started with backtesting on Aspis Protocol, check out our GitHub repository, where you can find the backtesting software along with detailed documentation on how to set it up and use it for your trading strategies.
Backtesting is a core component of quantitative finance and algorithmic trading. It involves running a trading strategy on historical data to evaluate its performance and risk profile before deploying it in a live environment. The main benefits of backtesting include:
Strategy Validation: By backtesting, traders can validate their strategies against past market data to ensure they work as expected.
Performance Optimization: It allows for fine-tuning of strategy parameters to maximize returns while minimizing risk.
Risk Management: By identifying potential drawdowns and periods of poor performance, traders can devise better risk management techniques.
However, it’s important to recognize that past performance does not guarantee future results. Real-world trading involves factors like slippage, latency, and changing market conditions that can affect strategy outcomes. Nonetheless, backtesting provides a valuable framework for narrowing down strategy choices and optimizing them for live trading.
The backtesting framework on Aspis Protocol is built upon the robust Basana library, an event-driven Python framework tailored for algorithmic trading. Our implementation extends Basana with essential features like:
Position Monitoring and Profit Calculation: Detailed tracking of open and closed positions, along with accurate profit and loss (P&L) calculations.
Risk Metrics: Automated calculation of key risk metrics such as maximum drawdown and the Sharpe Ratio.
Efficient Data Handling: A preprocessing script merges and formats historical data correctly, ensuring clean and consistent input for backtesting.
Multi-CPU Processing: A custom script leverages all CPU cores for backtesting, dramatically reducing computational time compared to Python’s default single-thread processing.
For those interested in the technical underpinnings of our approach, we recommend exploring the foundational concepts in event-driven backtesting systems as outlined by Lopez de Prado (2018) in "Advances in Financial Machine Learning".
We currently utilize the Binance Public Data API to retrieve historical market data for backtesting. You can access the API and its Python implementation in the official Binance Public Data repository on GitHub. This allows you to download and backtest any trading pairs available through Binance's extensive data offering. For demonstration purposes, we have preloaded some of the most popular pairs on Aspis Protocol, but traders are encouraged to explore and test any pair they choose.
This extensive dataset enables traders to test their strategies across different market regimes—bull, bear, and sideways—providing a comprehensive evaluation of strategy robustness.
For demonstrations purposes, Aspis Protocol provides a rich dataset covering popular trading pairs such as ETHUSDT, BTCUSDT, SOLUSDT, AVAXUSDT, BCHUSDT, BNBUSDT, DOGEUSDT, LTCUSDT, NEARUSDT, UNIUSDT across various timeframes:
Timeframes: 4H, 1H, 15M, 5M.
Data Span: From the inception of Binance in 2017 for most pairs, offering up to six years of historical data, which is crucial for robust backtesting.
This extensive dataset enables traders to test their strategies across different market regimes—bull, bear, and sideways—providing a comprehensive evaluation of strategy robustness.
To demonstrate the capabilities of Aspis Protocol’s backtesting environment, we created three foundational strategies: aspis_1, aspis_2, and aspis_3. These are built using popular indicators like Moving Average (MA), Relative Strength Index (RSI), and Bollinger Bands (BB):
aspis_1 - Mean Reversion Strategy: Buy Signal: RSI indicates oversold conditions, filtered by a price at least 1% above the MA. Sell Signal: RSI indicates overbought conditions.
aspis_2 - Trend Following Strategy: Buy Signal: Short-term MA crosses above the long-term MA, filtered by RSI. Sell Signal: Short-term MA crosses below the long-term MA, with an RSI filter.
aspis_3 - Scalping/StatArb Strategy: Buy Signal: Price is below the lower Bollinger Band with a short-term MA above a long-term MA. Sell Signal: Short-term MA falls below the long-term MA.
For traders interested in advanced parameter optimization, we recommend exploring Grid Search and Random Search techniques as discussed in Bergstra and Bengio (2012), "Random Search for Hyper-Parameter Optimization." These techniques can be applied to systematically adjust strategy parameters to find the most optimal configuration.
To maximize the potential of backtesting on Aspis Protocol:
Apply Machine Learning for Parameter Tuning: Utilize algorithms like Random Forests or Gradient Boosting Machines to automatically adjust strategy parameters for higher returns and lower risk.
Explore Reinforcement Learning Approaches: Use reinforcement learning (RL) algorithms, such as Deep Q-Learning (Mnih et al., 2015), to develop strategies that can adapt to market changes in real-time, learning from each trade and adjusting actions accordingly.
Run Extensive Sensitivity Analyses: Test strategies across various market conditions (volatile, trending, consolidating) and timeframes to understand their strengths and weaknesses.
The Sharpe Ratio remains one of the most critical metrics for evaluating a strategy's performance. However, other risk-adjusted return measures, such as the Sortino Ratio and Calmar Ratio, can provide deeper insights into strategy performance under different market conditions.
High Sharpe Ratios (> 1): Generally indicates a good balance between risk and reward.
Exceptional Sharpe Ratios (3-4): Highly desirable, demonstrating robust strategies that are likely to attract institutional interest.
I’ve run backtesting on current models on 1H and 4H timeframes and got the next results:
The results of backtesting on Aspis Protocol reveal several key insights:
Longer Timeframes Yield More Stable Results: For example, the Aspis 1, 4H timeframe on AVAX showed a profit of 128% over 4 years, with a Sharpe ratio of 0.69 and a maximum drawdown of 8%.
Importance of Contextual Factors: Results vary significantly across different pairs and market conditions, indicating the need for ongoing adjustment and monitoring.
Our backtesting results validate the effectiveness of the Aspis Protocol framework for testing and optimizing trading strategies. Moving forward, the integration of machine learning offers a new frontier for strategy enhancement:
Develop Adaptive Strategies: Using reinforcement learning and neural networks to build strategies that adapt dynamically to market conditions.
Continuous Learning and Improvement: Leveraging machine learning algorithms to continuously adjust parameters and adapt to changing market environments.
For further reading on machine learning applications in finance, consider "Machine Learning for Asset Managers" by Marcos Lopez de Prado (2020), which provides an in-depth look at practical algorithms for optimizing trading strategies.
By integrating these advanced tools and techniques, Aspis Protocol is positioned to provide DeFi traders with the cutting-edge resources needed to navigate the complexities of today’s financial markets.