Algorithmic Trading Model using Stochastic Oscillator with Different Signal Levels

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 employs a simple mean-reversion strategy using the Stochastic Oscillator indicator for the entry and exit signals. The model will use a 14 look-back period with a three-period Simple Moving Average (SMA) for the %K indicator. The model also will use a three-period SMA of the %K indicator for the %D indicator. Thus, the model will initiate a long position when the %D indicator crosses the lower signal line from above. Conversely, the model will exit the long position when the %D indicator crosses the upper signal line from below.

We will compare two trading models with different signal line widths. The first model will use 20/80 for the lower and upper signal lines. The second model will use a tighter 20/50 for the lower and upper signal lines.

ANALYSIS: In this modeling iteration, we analyzed ten stocks between August 1, 2016, and September 3, 2021. The models’ performance appeared at the end of the script. The models with the wider signal line width generally produced a better return for the tested stocks. Moreover, the simple buy-and-hold approach came out ahead for all stocks.

CONCLUSION: For most stocks during the modeling time frame, the long-only trading strategy with the Stochastic Oscillator signals did not produce a better return than the buy-and-hold approach. We should consider modeling these stocks 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.