Algorithmic Trading Model using Weekly MACD and RSI Indicators

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 Moving Average Convergence/Divergence Oscillator (MACD) and Relative Strength Index (RSI) for the entry and exit signals. For the MACD trend indicators, the model will use 12-week and 26-week periods for the MACD line. For the MACD signal line, we will use a 9-week EMA of the MACD line. Finally, the RSI will operate using a 14-week look-back period.

The model will signal for a long position when the MACD histogram switches from negative to positive, assuming the RSI signal is below the overbought threshold. Conversely, the model will look to initiate a short position when the signals reverse themselves.

We will compare two trading models with different buying approaches. The first model will use a long-only method, while the second model will take long and short positions. Both models will use a 10% stop-loss limit for each trade.

ANALYSIS: In this modeling iteration, we analyzed ten stocks between October 1, 2011, and October 1, 2021. The models’ performance appeared at the end of the script. The models with the long-only approach produced a better return than the long-short method. Moreover, the simple buy-and-hold system came out ahead for all stocks.

CONCLUSION: For most stocks during the modeling time frame, the customized trading strategy with the MACD and RSI 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.

Algorithmic Trading Model using Daily MACD and RSI Indicators

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 Moving Average Convergence/Divergence Oscillator (MACD) and Relative Strength Index (RSI) for the entry and exit signals. For the MACD trend indicators, the model will use 12-day and 26-day periods for the MACD line. For the MACD signal line, we will use a 9-day EMA of the MACD line. The RSI will operate using a 14-day look-back period.

The model will signal for a long position when the MACD histogram switches from negative to positive, assuming the RSI signal is below the overbought threshold. Conversely, the model will look to initiate a short position when the signals reverse themselves.

We will compare two trading models with different buying approaches. The first model will use a long-only method, while the second model will take long and short positions. Both models will use a 10% stop-loss limit for each trade.

ANALYSIS: In this modeling iteration, we analyzed ten stocks between October 1, 2011, and October 1, 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 customized trading strategy with the MACD and RSI 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.

Algorithmic Trading Model for Mean-Reversion with MACD Signals Using Python

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 Moving Average Convergence/Divergence (MACD) indicator as the entry and exit signals. The model will use a 26-period Exponential Moving Average (EMA), a 12-period EMA, and a nine-period EMA as the signal line for long trades only. The model will initiate a long position when the long EMA line crosses the signal line from below. Conversely, the model will exit the long position when the long EMA line crosses the signal line from above.

ANALYSIS: In this modeling iteration, we analyzed ten stocks between August 1, 2016, and August 27, 2021. The models’ performance appeared at the end of the script. Also, the models without stop-loss produced a better return six out of the ten stocks. Moreover, the simple buy-and-hold approach came out ahead for all stocks except one.

CONCLUSION: For most stocks during the modeling time frame, the long-only trading strategy with MACD 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.

Algorithmic Trading Model for Trend-Following with MACD Indicator Strategy Using Python Take 3

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.

From iteration Take1, we set up the models using a trend window size for long trades only. The window size varied from 10 to 20 trading days at a 5-day increment. We used 10 to 20 days for the fast EMA curve and 40 to 50 days for the slow EMA curve. The models also incorporated a volume indicator with a fixed window size of 10 days to confirm the buy/sell signal. Furthermore, we established a profit threshold of 15% and a loss threshold of 8%.

From iteration Take2, we set up the models using a trend window size for short trades only. The window size varied from 10 to 20 trading days at a 5-day increment. We used 10 to 20 days for the fast EMA curve and 40 to 50 days for the slow EMA curve. The models also incorporated a volume indicator with a fixed window size of 10 days to confirm the buy/sell signal. Furthermore, we established a profit threshold of 15% and a loss threshold of 8%.

In this Take3 iteration, we will set up the models using a trend window size for long and short trades. 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: From iteration Take1, 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.

From iteration Take2, 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 19.93 dollars per share. The buy-and-hold approach yielded a gain of 77.86 dollars per share.

In this Take3 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 70.80 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.

Algorithmic Trading Model for Trend-Following with MACD Indicator Strategy Using Python Take 2

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.

From iteration Take1, we set up the models using a trend window size for long trades only. The window size varied from 10 to 20 trading days at a 5-day increment. We used 10 to 20 days for the fast EMA curve and 40 to 50 days for the slow EMA curve. The models also incorporated a volume indicator with a fixed window size of 10 days to confirm the buy/sell signal. Furthermore, we established a profit threshold of 15% and a loss threshold of 8%.

In this Take2 iteration, we will set up the models using a trend window size for short 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: From iteration Take1, 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.

In this Take2 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 19.93 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.

Algorithmic Trading Model for Trend-Following with MACD Indicator 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 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.