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. This iteration of the modeling will focus on applying a trend-following or a momentum-oriented 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.
From iteration Take1, the grid search script searched through all combinations between the two sets of MA curves, simple and exponential. The faster MA curve ranged from 5 days to 30 days, while the slower MA ranged from 10 days to 60 days. Both curves used a 5-day increment.
For this Take2 iteration, the grid search script will search through all combinations between the four sets of MA curves. The four models are simple only, exponential only, fast simple/slow exponential, and fast exponential/slow simple. The fast MA curve can range from 5 days to 30 days, while the slower MA can range from 10 days to 60 days. Both curves use a 5-day increment.
ANALYSIS: From iteration Take1, we analyzed the stock prices for Apple Inc. (AAPL) between January 1, 2019 and August 3, 2020. The best simple MA model with 10-day and 20-day produced a profit of 284.11 per share. The best exponential MA model with 5-day and 20-day produced a gain of 280.73. The long-only approach yielded a profit of 280.86 per share.
For this Take2 iteration, we analyzed the stock prices for Apple Inc. (AAPL) between January 1, 2019 and August 3, 2020. The best MA model with 5-day EMA and 30-day SMA produced a profit of 289.28 per share. The long-only approach yielded a gain of 280.86 per share.
CONCLUSION: For this dataset, the combination of an exponential moving average curve of five days with a simple moving average curve of 30 days seem to produce the best profit level.
Dataset ML Model: Time series analysis with numerical attributes
Dataset Used: Quandl
The HTML formatted report can be found here on GitHub.