Algorithmic Trading Model using Weekly Price and Simple Moving Average 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 employs a simple strategy using the weekly price and simple moving average (SMA) for the entry and exit signals. For the SMA line, the model will use 25, 50, 75, and 100 days. The model will signal a long position when the weekly price crosses from below the SMA line to above. Conversely, the model will exit the long position when the weekly moves below the SMA line. The model will deploy all of its available capital per transaction to compare strategies.

ANALYSIS: In this modeling iteration, we analyzed thirteen Exchange-Traded Funds (ETF) for five years between January 1, 2017, and December 31, 2021. The models’ performance appeared at the end of the script. The buy-and-hold model generally produced a better return for the tested equities. The algorithmic trading model only comes out ahead with the energy sector ETF (XLE).

Amongst the moving average models, the 50-day model achieved the best results.

Buy-and-Hold: $150,303.80

25-day SMA: $43,853.16

50-day SMA: $54,411.06

75-day SMA: $51,384.59

100-day SMA: $26,551.52

SMA = 25

Buy_Hold_Return BH_Return_PCT BH_MAX_Drawdown Model_Return_VAL Model_Return_PCT Model_MAX_Drawdown

SPY       12877.5546      130.7275          0.0000        4097.0205          40.9702           -15.2550

QQQ       24586.6537      246.2731          0.0000       10218.5834         102.1858          -156.3498

XLB       10058.0173      100.7556      -1341.2387         -36.7190          -0.3672         -2656.6290

XLC        6086.7340       61.1607      -1931.8250        3555.1586          35.5516          -560.4453

XLE        -723.7860       -7.2649      -6116.7540        5178.1182          51.7812          -515.5180

XLF        8254.3023       82.6351      -1534.1967        -688.0155          -6.8802         -3886.3622

XLI        8488.9394       85.1742      -1300.3856        1343.5108          13.4351         -1748.8565

XLK       28015.9005      280.4021          0.0000       11079.4514         110.7945             0.0000

XLP        7058.5651       70.7087       -113.8109        1854.8170          18.5482           -38.0145

XLRE       9797.9809       98.1428       -267.4271         386.0426           3.8604         -2354.5343

XLU        7366.0707       73.7749        -22.7373        1055.4053          10.5541          -453.0287

XLV       12094.9515      121.4858          0.0000         941.6611           9.4166         -1037.0731

XLY       16341.9195      163.5815          0.0000        4868.1323          48.6813          -246.8632

SMA = 50

Buy_Hold_Return BH_Return_PCT BH_MAX_Drawdown Model_Return_VAL Model_Return_PCT Model_MAX_Drawdown

SPY       12877.5546      130.7275          0.0000        5308.2378          53.0824           -15.2550

QQQ       24586.6537      246.2731          0.0000       12737.0915         127.3709             0.0000

XLB       10058.0173      100.7556      -1341.2387        -132.1118          -1.3211         -1025.3787

XLC        6086.7340       61.1607      -1931.8250        2947.1054          29.4711          -318.3278

XLE        -723.7860       -7.2649      -6116.7540        4316.2861          43.1629         -1302.4730

XLF        8254.3023       82.6351      -1534.1967         642.7439           6.4274         -1780.0172

XLI        8488.9394       85.1742      -1300.3856        1473.5733          14.7357         -1061.1170

XLK       28015.9005      280.4021          0.0000       14795.0697         147.9507             0.0000

XLP        7058.5651       70.7087       -113.8109        2056.0999          20.5610          -168.0443

XLRE       9797.9809       98.1428       -267.4271        1643.2901          16.4329         -1051.2054

XLU        7366.0707       73.7749        -22.7373        -480.1260          -4.8013          -979.0842

XLV       12094.9515      121.4858          0.0000        1627.9453          16.2795          -430.0784

XLY       16341.9195      163.5815          0.0000        7475.8599          74.7586             0.0000

SMA = 75

Buy_Hold_Return BH_Return_PCT BH_MAX_Drawdown Model_Return_VAL Model_Return_PCT Model_MAX_Drawdown

SPY       12877.5546      130.7275          0.0000        5377.6900          53.7769             0.0000

QQQ       24586.6537      246.2731          0.0000        8470.7960          84.7080          -337.9920

XLB       10058.0173      100.7556      -1341.2387        2155.4260          21.5543          -911.9216

XLC        6086.7340       61.1607      -1931.8250        6026.6871          60.2669           -13.4357

XLE        -723.7860       -7.2649      -6116.7540         763.1591           7.6316         -2461.8256

XLF        8254.3023       82.6351      -1534.1967        3190.6586          31.9066          -355.4903

XLI        8488.9394       85.1742      -1300.3856        1850.3269          18.5033          -366.5802

XLK       28015.9005      280.4021          0.0000        7299.2418          72.9924          -352.3613

XLP        7058.5651       70.7087       -113.8109        2394.2547          23.9425           -38.0145

XLRE       9797.9809       98.1428       -267.4271        5188.4688          51.8847          -246.4546

XLU        7366.0707       73.7749        -22.7373        1024.6837          10.2468          -502.6518

XLV       12094.9515      121.4858          0.0000         952.9627           9.5296         -1395.3537

XLY       16341.9195      163.5815          0.0000        6690.2355          66.9024           -72.1826

SMA = 100

Buy_Hold_Return BH_Return_PCT BH_MAX_Drawdown Model_Return_VAL Model_Return_PCT Model_MAX_Drawdown

SPY       12877.5546      130.7275          0.0000         411.8029           4.1180          -469.4300

QQQ       24586.6537      246.2731          0.0000        2555.0782          25.5508           -60.6627

XLB       10058.0173      100.7556      -1341.2387       -1105.1112         -11.0511         -1366.3663

XLC        6086.7340       61.1607      -1931.8250        7824.3660          78.2437           -60.7521

XLE        -723.7860       -7.2649      -6116.7540         440.9515           4.4095         -2717.9478

XLF        8254.3023       82.6351      -1534.1967        1916.5176          19.1652         -1881.6719

XLI        8488.9394       85.1742      -1300.3856        3611.8204          36.1182          -986.2365

XLK       28015.9005      280.4021          0.0000        5922.2349          59.2223          -132.4859

XLP        7058.5651       70.7087       -113.8109         305.2303           3.0523          -800.5252

XLRE       9797.9809       98.1428       -267.4271        1426.8374          14.2684         -1412.7599

XLU        7366.0707       73.7749        -22.7373         411.9854           4.1199          -744.8940

XLV       12094.9515      121.4858          0.0000         924.9504           9.2495         -1070.3463

XLY       16341.9195      163.5815          0.0000        1904.8643          19.0486           -72.1826

CONCLUSION: For most stocks during the modeling time frame, the customized trading strategy with the Weekly Price and Simple Moving Average did not produce a better return than the buy-and-hold approach. We should consider modeling these stocks further by experimenting with more strategy variations.

Dataset ML Model: Time series analysis with numerical attributes

Dataset Used: Sharadar US Equities and Fund Prices hosted by Quandl/Nasdaq Data Link

The HTML formatted report can be found here on GitHub.

Algorithmic Trading Model using Weekly Price and Simple Moving Average 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 employs a simple strategy using the weekly price and simple moving average (SMA) for the entry and exit signals. For the SMA line, the model will use 50 days. The model will signal a long position when the weekly price crosses from below the SMA line to above. Conversely, the model will exit the long position when the weekly moves below the SMA line. The model will deploy all of its available capital per transaction to compare strategies.

ANALYSIS: In this modeling iteration, we analyzed thirteen Exchange-Traded Funds (ETF) for five years between January 1, 2017, and December 31, 2021. The models’ performance appeared at the end of the script. The buy-and-hold model generally produced a better return for the tested equities. However, the algorithmic trading model only comes out ahead with the energy sector ETF (XLE).

CONCLUSION: For most stocks during the modeling time frame, the customized trading strategy with the Weekly Price and Simple Moving Average did not produce a better return than the buy-and-hold approach. We should consider modeling these stocks further by experimenting with more strategy variations.

Dataset ML Model: Time series analysis with numerical attributes

Dataset Used: Sharadar US Equities and Fund Prices hosted by Quandl/Nasdaq Data Link

The HTML formatted report can be found here on GitHub.

Algorithmic Trading Model using Weekly Price and Simple Moving Average 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 employs a simple strategy using the weekly price and simple moving average (SMA) for the entry and exit signals. For the SMA line, the model will use 50 days. The model will signal a long position when the weekly price crosses from below the SMA line to above. Conversely, the model will exit the long position when the weekly moves below the SMA line. The model will purchase one stock per transaction to compare strategies.

ANALYSIS: In this modeling iteration, we analyzed thirteen Exchange-Traded Funds (ETF) for five years between January 1, 2017, and December 31, 2021. The models’ performance appeared at the end of the script. The buy-and-hold model generally produced a better return for the tested equities. However, the algorithmic trading model only comes out ahead with the energy sector ETF (XLE).

CONCLUSION: For most stocks during the modeling time frame, the customized trading strategy with the Weekly Price and Simple Moving Average did not produce a better return than the buy-and-hold approach. We should consider modeling these stocks further by experimenting with more strategy variations.

Dataset ML Model: Time series analysis with numerical attributes

Dataset Used: Sharadar US Equities and Fund Prices hosted by Quandl/Nasdaq Data Link

The HTML formatted report can be found here on GitHub.

Algorithmic Trading Model for Trend-Following with RSI Exit Signal for a Group of Stocks 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 compares a simple trend-following strategy with or without using RSI as the exit signal for an individual stock. The model will use a trend window size of ten days for long trades only. When the 14-day RSI value reaches 70, the model will exit the long position.

ANALYSIS: In this modeling iteration, we analyzed 14 stocks between January 1, 2016, and July 26, 2021. The models’ performance appeared at the end of the script.

CONCLUSION: For all the stocks during the modeling time frame, the long-only trading strategy with or without RSI as the exit signal did not produce a better return than the buy-and-hold approach, except for Citigroup (C), Southwest Airlines (LUV), and Wells Fargo Bank (WFC). 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 RSI Exit Signal for an Individual Stock 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 compares a simple trend-following strategy with or without using RSI as the exit signal for an individual stock. The model will use a trend window size of ten days for long trades only. When the 14-day RSI value reaches 70, the model will exit the long position.

ANALYSIS: In this modeling iteration, we analyzed the stock of AAPL (Apple Inc.) between January 1, 2016, and July 26, 2021. The mean-reversion model without using RSI produced a profit of 51.55 dollars per share, while the model with RSI signals returned 90.01. In addition, the buy-and-hold approach yielded a gain of 122.61 dollars per share.

CONCLUSION: For the AAPL stock during the modeling time frame, the long-only trading strategy with or without RSI as the exit signal did not produce a better return than the buy-and-hold approach. We should consider 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 vs. Trend-Following Strategy for a Group of Stocks 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 compares a simple mean-reversion and trend-following strategy for a group of stocks. The model will use a trend window size of ten days for long trades only.

ANALYSIS: In this modeling iteration, we analyzed ten stocks between January 1, 2016, and July 9, 2021. The models’ performance appeared at the end of the script.

CONCLUSION: For all the stocks during the modeling time frame, the long-only trading strategy with either mean-reversion or trend-following approach did not produce a better return than the buy-and-hold approach, except for LUV and PFE. 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 vs. Trend-Following Strategy for an Individual Stock 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 compares a simple mean-reversion strategy with a trend-following for a single stock. The model will use a trend window size of ten days for long trades only.

ANALYSIS: In this modeling iteration, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2016, and July 9, 2021. The mean-reversion model produced a profit of 101.20 dollars per share, while the trend-following model returned a profit of 154.21. The buy-and-hold approach yielded a gain of 248.74 dollars per share.

CONCLUSION: For the COST stock during the modeling time frame, the long-only trading strategy with either mean-reversion or trend-following approach 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 Bollinger Bands Strategy Using Python Take 4

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 mean-reversion strategy for a stock. The model enters a position when the price reaches either the upper or lower Bollinger Bands for the last X number of days. The model will exit the trade when the stock price crosses the middle Bollinger Band of the same window size.

In iteration Take1, we 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, and we fixed the Bollinger Band factor at 2.0.

In iteration Take2, we set up the models using a trend window size for long and short trades. The window size varied from 10 to 50 trading days at a 5-day increment, and we fixed the Bollinger Band factor at 2.0.

In iteration Take3, we experimented with different Bollinger Band factors from 1.0 to 3.0. The models still used a trend window size for long trades only. The window size varied from 10 to 50 trading days at a 5-day increment.

In this Take4 iteration, we will experiment with different Bollinger Band factors from 1.0 to 3.0. The models will use a trend window size for long and short trades. The window size will vary from 10 to 50 trading days at a 5-day increment.

ANALYSIS: In iteration Take1, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2016, and May 7, 2021. The top trading model produced a profit of 101.66 dollars per share. The buy-and-hold approach yielded a gain of 223.02 dollars per share.

In iteration Take2, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2016, and May 7, 2021. The top trading model produced a profit of -1.26 dollars per share. The buy-and-hold approach yielded a gain of 223.02 dollars per share.

In iteration Take3, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2016, and May 7, 2021. The top trading model produced a profit of 138.21 dollars per share. The buy-and-hold approach yielded a gain of 223.02 dollars per share.

In this Take4 iteration, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2016, and May 7, 2021. The top trading model produced a profit of 42.91 dollars per share. The buy-and-hold approach yielded a gain of 223.02 dollars per share.

CONCLUSION: For the stock of COST during the modeling time frame, the long-and-short trading strategy with variable Bollinger Band factors 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.