Algorithmic Trading Model for Trend-Following with Holding Period Strategy Using Python Take 1

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 buys a stock when the price reaches the highest price for the last X number of days. The model will exit the position when the stock price crosses below the mean of the same window size.

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 fixed holding window. The system will exit the position when the holding window reaches the maximum window size.

In this Take1 iteration, we will set up the models using a trend window size for long trades only. The window size varied from 10 to 50 trading days at a 5-day increment. The models will also consider a volume indicator with a varying window size between 10 and 15 days to further confirm the buy/sell signal. We will not limit the holding period by setting the maximum holding period to 99 days for this iteration.

ANALYSIS: In this Take1 iteration, we analyzed the stock prices for Apple Inc. (AAPL) between January 1, 2018, and December 31, 2020. The trading model produced a profit of 95.90 dollars per share. The buy-and-hold approach yielded a gain of 91.54 dollars per share.

CONCLUSION: For the stock of AAPL during the modeling time frame, the trading strategy produced a slightly 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.