Algorithmic Trading Model for Simple Momentum Strategy Using Python Take 2

SUMMARY: The purpose of this project is to construct and test an algorithmic trading model and document the end-to-end steps using a template.

Additional Notes: This is an adaptation of the momentum trading strategy from Chapter 2 of Learn Algorithmic Trading by Sebastien Donadio and Sourav Ghosh with Packt Publishing.

INTRODUCTION: This algorithmic trading model uses the support and resistance levels to generate trading signals for a momentum trading strategy. The strategy is to create a buy order when the stock price stays in the resistance tolerance margin after a waiting period. Conversely, the model generates a signal for a sell order when the stock price remains in the support tolerance margin after the same waiting period.

We apply the analysis on a stock for a fixed period and compare its return/loss to a simple long-only model. The long-only model will purchase the stock at the opening of day one and hold the stock through the entire time.

In iteration Take1, we constructed and tested a momentum trading model for the stock “GOOG” during the three years between 2017 and 2019 with an investment pool of 1,500 USD.

In this Take2 iteration, we will construct and test a momentum trading model for the stock “GOOG” during the three years between 2017 and 2019 with an investment pool of 1,500 USD. Instead, we will change the waiting period from two days to just one day.

ANALYSIS: In this Take1 iteration, the momentum trading strategy returned 30.18%. In the meantime, the long-only approach achieved an accumulated return of 37.16%.

In this Take2 iteration, the momentum trading strategy with a waiting period of one day returned 16.36%.

The trading strategy with a waiting period of three days returned 21.70%.

The trading strategy with a waiting period of four days returned 27.16%.

The trading strategy with a waiting period of five days returned 27.62%.

CONCLUSION: For this period, the momentum trading strategy did not outperform the more straightforward long-only approach, so we should consider modeling more and different methods 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.

Time Series Model for Monthly Shampoo Sales Using Python and ETS

Template Credit: Adapted from a template made available by Dr. Jason Brownlee of Machine Learning Mastery.

SUMMARY: The purpose of this project is to construct a time series prediction model and document the end-to-end steps using a template. The Monthly Shampoo Sales dataset is a time series situation where we are trying to forecast future outcomes based on past data points.

INTRODUCTION: The problem is to forecast the monthly number of shampoo sales. The dataset described a time-series of monthly shampoo sales for three years, and there are 36 observations. We will use the first 24 observations for training the model while using the remaining 12 observations for testing the model.

ANALYSIS: The ETS model, which models multiplicative trend with no trend dampening, no BoxCox transform, and no bias removal, appeared to have the lowest RMSE at 83.72.

CONCLUSION: For this dataset, the chosen ETS model achieved a satisfactory result and should be considered for further modeling.

Dataset Used: Sales of shampoo over a three-year period

Dataset ML Model: Time series forecast with numerical attributes

Dataset Reference: Rob Hyndman and Yangzhuoran Yang (2018). tsdl: Time Series Data Library. v0.1.0. https://pkg.yangzhuoranyang./tsdl/

The HTML formatted report can be found here on GitHub.

Algorithmic Trading Model for Simple Momentum Strategy Using Python Take 1

SUMMARY: The purpose of this project is to construct and test an algorithmic trading model and document the end-to-end steps using a template.

Additional Notes: This is an adaptation of the momentum trading strategy from Chapter 2 of Learn Algorithmic Trading by Sebastien Donadio and Sourav Ghosh with Packt Publishing.

INTRODUCTION: This algorithmic trading model uses the support and resistance levels to generate trading signals for a momentum trading strategy. The strategy is to create a buy order when the stock price stays in the resistance tolerance margin for two consecutive days. Conversely, the model generates a signal for a sell order when the stock price stays in the support tolerance margin for two straight days.

We apply the analysis on a stock for a fixed period and compare its return/loss to a simple long-only model. The long-only model will purchase the stock at the opening of day one and hold the stock through the entire time.

In this Take1 iteration, we will construct and test a momentum trading model for the stock “GOOG” during the three years between 2017 and 2019 with an investment pool of 1,500 USD.

ANALYSIS: In this Take1 iteration, the momentum trading strategy returned 30.18%. In the meantime, the long-only approach achieved an accumulated return of 37.16%.

CONCLUSION: For this period, the momentum trading strategy did not outperform the more straightforward long-only approach, so we should consider modeling more and different methods 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.

ARIMA Time Series Modeling Project Template for Python Version 6

As I work on practicing and solving machine learning (ML) problems, I find myself repeating a set of steps and activities repeatedly.

Thanks to Dr. Jason Brownlee’s suggestions on creating a machine learning template, I have pulled together a project template that can be used to support time series analysis using the ARIMA modeling and Python.

Version 6 of the time series template contains minor adjustments and corrections to the prevision version of the template. Also, the new template added and updated the sample code to support:

  • Downloading data from the Federal Reserve Bank’s FRED database.
  • A more flexible out-of-sample forecasting length. The forecasting size used to be equal to the test data size by default.

You will find the Python time series template on the Machine Learning Project Templates page.

Kathy Sierra on Making Users Awesome, Part 8

In the book, Badass: Making Users Awesome, Kathy Sierra analyzed and discussed the new ways of thinking about designing and sustaining successful products and services.

These are some of my takeaways from reading the book.

Up to this point, Kathy discussed how we could help our users keep wanting to and get better at a skill. We can help them by assisting them to practice right and gain exposure to the right things.

We can also help them focus on what motivation path and payoffs they would need and what would make them stop the forward progress. But we will need one primary ingredient to make it all work. That ingredient is the users’ cognitive processing capacity.

Based on prior researches, we know this one thing about our cognitive processing capacity.

Willpower and cognitive processing draw from the same pool of mental resources.

If that is the case, Kathy asserted that we should always be asking, “where do my users want to spend their precious cognitive resources? What can we do to help? What are we doing that hurts?”

Remember that users ultimately care about the “compelling context.” We should construct our product/service in a way that it stops stealing cognitive resources from the users.

We want our users to use cognitive resources when interacting with our product/service.

We do not want our users to waste them, so don’t make them think about the wrong things when they interact with our product/service.

慷慨並不總表示免費

(從我一個尊敬的作家,賽斯·高汀

這些年來,人們一直都是很慷慨。那位花時間去多了解您的病痛的醫生。一個毫不猶豫,甚至在您知道需要之前就為您提供了所需的東西的服務員。一位在適當的時候給您一個項目的老闆。

禮物能創造聯繫和可能性,但並非所有禮物都具有貨幣價值。實際上,人生中一些最重要的禮物反而是涉及時間,精力和護理。

人們在到這宇宙很久以後才發明了錢,而商業也並不能解決所有的問題。

在這一刻,我們如此脫節和恐懼時,答案可能不是光免費的,那更可能會使我們進一步分開。答案可能是出現在做出難以完成的連接,表現關懷,和擴展自己的工作上。

Algorithmic Trading Model for “Buy Low Sell High” Using Python Take 4

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 daily close prices to generate trading signals. If the stock closes lower for the day, we will purchase at the opening of the next trading day if we did not have the stock on-hand. If the stock closes higher for the day, we will sell the stock at the opening of the next day if we have the stock on-hand. We will take no action if we encounter the trading signal to sell but have no stock on-hand or the trading signal to buy if we already have the stock on-hand.

We apply the analysis on a stock for a fixed period and compare its return/loss to a simple long-only model. The long-only model will purchase the stock at the opening of day one and hold the stock through the entire time.

In iteration Take1, we constructed and tested the trading model for the stock “GOOG” during the year of 2019.

In iteration Take2, we constructed and tested the trading model for the stock “GOOG” during the year of 2018.

In iteration Take3, we modified the strategy by imposing a “waiting window” and tested the trading model for the stock “GOOG” during the year of 2019. The waiting window enforced one day of no action right after we buy or sell. We also observed whether the waiting window can improve our results over the previous strategy.

In this Take4 iteration, we will apply the modified strategy for the year of 2018. We will observe whether the waiting window can improve our results over the previous strategy.

ANALYSIS: In iteration Take1 and during 2019, the “Buy Low Sell High” strategy returned 12.38%. In the meantime, the long-only approach achieved an accumulated return of 15.98%.

In iteration Take2 and during 2018, the “Buy Low Sell High” strategy returned -4.57%. In the meantime, the long-only approach achieved an accumulated return of -0.56%. The long-only method turned out to be a better choice again.

In iteration Take3 and during 2019, the “Buy Low Sell High” strategy returned 13.54%. In the meantime, the long-only approach achieved an accumulated return of 15.98%. The long-only method turned out to be a better choice again. However, the waiting window did improve our buy-low-sell-high strategy as well.

In this Take4 iteration and during 2018, the “Buy Low Sell High” strategy returned -2.38%. In the meantime, the long-only approach achieved an accumulated return of -0.56%. The long-only method turned out to be a better choice again. However, the waiting window did improve our buy-low-sell-high strategy as well.

CONCLUSION: For this period, the “Buy Low Sell High” strategy did not exceed the more straightforward long-only approach, so we should consider modeling more and different methods 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.

Algorithmic Trading Model for “Buy Low Sell High” Using Python Take 3

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 daily close prices to generate trading signals. If the stock closes lower for the day, we will purchase at the opening of the next trading day if we did not have the stock on-hand. If the stock closes higher for the day, we will sell the stock at the opening of the next day if we have the stock on-hand. We will take no action if we encounter the trading signal to sell but have no stock on-hand or the trading signal to buy if we already have the stock on-hand.

We apply the analysis on a stock for a fixed period and compare its return/loss to a simple long-only model. The long-only model will purchase the stock at the opening of day one and hold the stock through the entire time.

In iteration Take1, we constructed and tested the trading model for the stock “GOOG” during the year of 2019.

In iteration Take2, we constructed and tested the trading model for the stock “GOOG” during the year of 2018.

In this Take3 iteration, we will modify the strategy by imposing a “waiting window” and test the trading model for the stock “GOOG” during the year of 2019. The waiting window will enforce one day of no action right after we buy or sell. We will observe whether the waiting window can improve our results over the previous strategy.

ANALYSIS: In iteration Take1 and during 2019, the “Buy Low Sell High” strategy returned 12.38%. In the meantime, the long-only approach achieved an accumulated return of 15.98%.

In iteration Take2 and during 2018, the “Buy Low Sell High” strategy returned -4.57%. In the meantime, the long-only approach achieved an accumulated return of -0.56%. The long-only method turned out to be a better choice again.

In this Take3 iteration and during 2019, the “Buy Low Sell High” strategy returned 13.54%. In the meantime, the long-only approach achieved an accumulated return of 15.98%. The long-only method turned out to be a better choice again. However, the waiting window did improve our buy-low-sell-high strategy as well.

CONCLUSION: For this period, the “Buy Low Sell High” strategy did not exceed the more straightforward long-only approach, so we should consider modeling more and different methods 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.