# Algorithmic Trading Model with Dual Moving Average Crossover Using Python Take 4

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 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 Take2, we developed a trading model by constructing the coding segments to process the stock pricing data and generate trading signals.

In iteration Take3, we used the trading signals to “backtest” and evaluate the trading model by comparing the strategy with a long-only approach. We employed the “Go Flat” approach by selling the stocks we bought earlier when the trading signal reverses.

In this Take4 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 Short” approach by shorting the stocks we bought earlier when the trading signal reverses.

ANALYSIS: In iteration Take3, the long-only approach achieved an accumulated return of 2.5550%. In the meantime, the SMA crossover strategy returned 2.2036%.

In this Take4 iteration, the long-only approach achieved an accumulated return of 2.5550%. In the meantime, the SMA crossover strategy returned 1.9005%.

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.