Algorithmic Trading Model using Weekly MACD and RSI Indicators

NOTE: This script is for learning purposes only and does not constitute a recommendation for buying or selling any stock mentioned in this script.

SUMMARY: This project aims to construct and test an algorithmic trading model and document the end-to-end steps using a template.

INTRODUCTION: This algorithmic trading model employs a simple mean-reversion strategy using the Moving Average Convergence/Divergence Oscillator (MACD) and Relative Strength Index (RSI) for the entry and exit signals. For the MACD trend indicators, the model will use 12-week and 26-week periods for the MACD line. For the MACD signal line, we will use a 9-week EMA of the MACD line. Finally, the RSI will operate using a 14-week look-back period.

The model will signal for a long position when the MACD histogram switches from negative to positive, assuming the RSI signal is below the overbought threshold. Conversely, the model will look to initiate a short position when the signals reverse themselves.

We will compare two trading models with different buying approaches. The first model will use a long-only method, while the second model will take long and short positions. Both models will use a 10% stop-loss limit for each trade.

ANALYSIS: In this modeling iteration, we analyzed ten stocks between October 1, 2011, and October 1, 2021. The models’ performance appeared at the end of the script. The models with the long-only approach produced a better return than the long-short method. Moreover, the simple buy-and-hold system came out ahead for all stocks.

CONCLUSION: For most stocks during the modeling time frame, the customized trading strategy with the MACD and RSI signals did not produce a better return than the buy-and-hold approach. We should consider modeling these stocks further by experimenting with more variations of the strategy.

Dataset ML Model: Time series analysis with numerical attributes

Dataset Used: Quandl

The HTML formatted report can be found here on GitHub.