Algorithmic Trading: Backtesting of different trading strategies

Algorithmic Trading: Backtesting of different trading strategies
Source: https://inlab.fib.upc.edu/en/blog/what-algorithmic-trading/2022/

Over time, trading has grown increasingly popular. More people than ever before are investing money in assets like stocks, ETFs (Exchange Traded Funds) or bonds. With the continuous technological advancements and digitalization in the financial sector, access to financial instruments became easier. This trend continued and went as far as today, where technology allows millions of market participants to connect from all around the world and trade securities from a variety of devices and platforms. Today, most of the trading process is automated and does not require any human interaction like the handling of an order book. But what remains to be automated on a broader scale is the decision-making process of when to buy or sell an asset. This is the problem of traditional, manual trading: It can take large amounts of time and require fundamental knowledge about the economy, the markets, and the used instruments. Algorithmic trading seeks to close this gap of automation in the investment process and encompasses the analysis of the asset as well as identifying trading signals and acting upon them.

Goals

As exiting literature does not provide helpful insights in the effectiveness of algorithmic trading, this thesis aimed to test different trading strategies over a longer period of time. Therefore, the four following strategies were chosen to be compared to a simple passive buy-and-hold strategy:

  • A volatility and volume threshold strategy: A strategy, where buy and sell signals are derived from a volatility- and volume threshold.
  • A relative volatility index strategy: A strategy, where a relative volatility index is constructed to determine buy and sell signals.
  • A combination of a random forest, mean reversion, and Z-score strategy: This strategy uses a random forest regressor to determine the most important features of the security and derives trading signals by the rolling mean and z-score.
  • A combination of these 3 strategies with a voting on buy and sell signals: This strategy combines the three strategies and acts depending on the signals of all of them.

The goal was to find out, which strategies performed best in terms of performance and how the combination of multiple strategies affected said performance.

Methodology

This methodology consisted of 5 major parts.

  • The first part was about defining the selected strategies. This contained the definition of how it acts, what it interprets as buy and sell signals and what parameters the strategies have. A parameter represented a constant of the strategy which could be set later on. As an example, in the first strategy, the threshold for the volatility was a parameter which could be set with any desired value. Every strategy had multiple parameters which were allocated in the second part.
  • This second part defined multiple values for each parameter. This resulted in multiple different variations of each strategy with differences in their parameter values. In total, 789 different variations were used for each tested asset.
  • The third part consisted of the implementation of the defined algorithms in an application which was written from scratch for this thesis. The application also included a web-interface for configuring the strategies and analyzing their results. The strategies as well as the engine for testing the strategies against historical data was written in python with the help of the library "Backtrader". The web-interface on the other hand was written in TypeScript, HTML, CSS with the "Angular" framework.
  • The fourth part represented the testing of the strategies with the developed software. For that, the values for the parameters which were defined in the second part, were configured in the application. All variations were tested with three different assets: The Tesla stock, an emerging markets stock index fund, and gold futures. The testing period was set to a span of 13 years (start of 2011 until the end of 2023). The code of the application can be found in the following repository: https://bitbucket.org/Fabian_Rutishauser/bbth/src/main/
  • The fifth step consisted of the comparison of the results. The performance of all the variations was compared to the benchmark and the impact of the combination-strategy was analyzed.

Results

The performed simulation showed that the implemented and tested strategies can result in a positive return. It even proved that such strategies potentially outperform a passive investment approach in the long run. In addition, combining the tested strategies mostly lead to an improvement in performance. However, an indication of common pattern for certain parameters, which lead to the best result, could be found. This implies that to trade in the real market, the best strategy needs to be found by running historic simulations. For effectively using those strategies in the long run it is recommended to implement a mechanism which can update the used strategy at runtime. The developed application can serve as a foundation for testing one’s own strategies and even for implementing mechanisms to trade on real markets.

Top 10 best performing variations for the emerging markets index fund
Fabian Rutishauser
by Fabian Rutishauser

Supervisors: Prof. Dr. Raúl Diego Gimeno and Prof. Dr. Branka Hadji Misheva