Code Credit: Adapted from code samples used in O’Reilly Media’s Learning Path: Hands-On Algorithmic Trading with Python by Deepak Kanungo.
SUMMARY: The purpose of this project is to construct an algorithmic trading model and document the end-to-end steps using a template.
INTRODUCTION: This algorithmic trading model uses the 20-day and 50-day moving averages to generate trading signals. When the dual moving average crossover signal is positive, the strategy goes long (buys) the stock. When the opposite occurs, we can either exit the position or short the stock. We apply the analysis on the MSFT stock for the three years of 2017-01-01 thru 2019-12-31.
In iteration Take1, we constructed the code modules to cover the tasks of downloading the daily price information for a stock symbol.
In iteration Take2, we developed a trading model by constructing the coding segments to process the stock pricing data and generate trading signals.
In this Take3 iteration, we will use the trading signals to “backtest” and evaluate the trading model by comparing the strategy with a long-only approach. We will employ the “Go Flat” approach by selling the stocks we bought earlier when the trading signal reverses.
ANALYSIS: The long-only approach achieved an accumulated return of 2.5550%. In the meantime, the SMA crossover strategy returned 2.2036%.
CONCLUSION: For this period, the SMA crossover strategy did not exceed the more straightforward long-only approach, so we should consider different models for this stock.
Dataset ML Model: Time series analysis with numerical attributes
Dataset Used: Various sources as illustrated below.
Dataset Reference: Various sources as documented below.
The HTML formatted report can be found here on GitHub.