Algorithmic Trading Model for Momentum and Mean-Reversion Moving Average Crossover Grid Search

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: The purpose of this project is to construct and test an algorithmic trading model and document the end-to-end steps using a template.

INTRODUCTION: This algorithmic trading model examines a series of exponential and simple moving average (MA) crossover models via a grid search methodology. The MA models fall under one of two trading approaches: momentum and mean-reversion. This iteration of modeling will focus on applying four different MA models to each approach.

For the momentum approach, when the fast moving-average curve crosses above the slow moving-average curve, the strategy goes long (buys) on the stock. When the opposite occurs, we will exit the position. For the mean-reversion approach, the strategy goes long (buys) when the fast moving-average curve crosses below the slow moving-average curve.

ANALYSIS: From this iteration, we analyzed the stock prices for Apple Inc. (AAPL) between January 1, 2019 and August 28, 2020. The best mean-reversion model with 30-day fast SMA and 35-day slow EMA produced a profit of 134.18 per share. The best momentum MA model with 15-day fast EMA and 25-day slow SMA produced a gain of 351.89. The long-only approach yielded a gain of 344.34 per share.

CONCLUSION: For AAPL and during the modeling time frame, the momentum-oriented approach produced an excellent return when compared to the mean-reversion and long-only approaches. In this case, we should consider deploying the momentum models when trading the AAPL stocks.

Dataset ML Model: Time series analysis with numerical attributes

Dataset Used: Quandl

The HTML formatted report can be found here on GitHub.