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 examines a simple trend-following strategy for a stock. The model enters a position when the price reaches either the highest or the lowest points for the last X number of days. The model will exit the trade when the stock’s MACD histogram switches side.
In addition to the stock price, the models will also use the trading volume indicator to confirm the buy/sell signal further. Finally, the strategy will also incorporate a profit/loss threshold. The strategy will exit the position when the profit or the loss has reached the threshold.
In this Take1 iteration, we will set up the models using a trend window size for long trades only. The window size will vary from 10 to 20 trading days at a 5-day increment. We will use 10 to 20 days for the fast EMA curve and 40 to 50 days for the slow EMA curve. The models will also incorporate a volume indicator with a fixed window size of 10 days to confirm the buy/sell signal. Furthermore, we will establish a profit threshold of 15% and a loss threshold of 8%.
ANALYSIS: In this Take1 iteration, we analyzed the stock prices for Apple Inc. (AAPL) between January 1, 2018, and March 12, 2021. The top trading model produced a profit of 56.72 dollars per share. The buy-and-hold approach yielded a gain of 77.86 dollars per share.
CONCLUSION: For the stock of AAPL during the modeling time frame, the long trading strategy with profit/loss limits did not produce a better return than the buy-and-hold approach. We should consider modeling this stock 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.