Algorithmic Trading Model for Trend-Following with APO 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 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 absolute price oscillator (APO) 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 loss has reached the established 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 an APO indicator with a range of plus and minus 2 to 4 dollars. Furthermore, we established a profit cap 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 an APO indicator with a range of plus and minus 2 to 4 dollars. Furthermore, we established a profit cap of 15% and a loss threshold of 8%.

In this Take3 iteration, we will set up the models using a trend window size for both 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 an APO indicator with a range of plus and minus 2 to 4 dollars. Furthermore, we will establish a profit cap of 15% and a loss threshold of 8%.

ANALYSIS: From iteration Take1, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2018, and March 19, 2021. The top trading model produced a profit of 136.38 dollars per share. The buy-and-hold approach yielded a gain of 109.12 dollars per share.

From iteration Take2, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2018, and March 19, 2021. The top trading model produced a profit of 136.38 dollars per share. The buy-and-hold approach yielded a gain of 109.12 dollars per share.

In this Take3 iteration, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2018, and March 19, 2021. The top trading model produced a profit of 136.38 dollars per share. The buy-and-hold approach yielded a gain of 110.16 dollars per share.

CONCLUSION: For the stock of COST during the modeling time frame, the long-and-short 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.

Multi-Class Image Classification Deep Learning Model for Textile Defect Detection Using TensorFlow Take 2

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

SUMMARY: This project aims to construct a predictive model using a TensorFlow convolutional neural network (CNN) and document the end-to-end steps using a template. The Textile Defect Detection dataset is a multi-class classification situation where we attempt to predict one of several (more than two) possible outcomes.

INTRODUCTION: This dataset from Kaggle contains 96,000 patches of the textile image with different quality problems. The goal of the exercise is to detect the quality issue for a patch of textile during production. The greyscale photos are part of the public dataset made available by the MVTec Company and referred by the research paper from Paul Bergmann, Michael Fauser, David Sattlegger, Carsten Steger. MVTec AD – A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection; in: IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2019.

From iteration Take1, we constructed a CNN model using a simple three-block VGG architecture and tested the model’s performance using a separate test dataset.

In this Take2 iteration, we will construct a CNN model using the DenseNet201 architecture and test the model’s performance using a separate test dataset.

ANALYSIS: From iteration Take1, the baseline model’s performance achieved an accuracy score of 97.07% on the validation dataset after 15 epochs. Furthermore, the final model’s performance achieved an accuracy score of 68.03% on the test dataset after 15 epochs.

In this Take2 iteration, the DenseNet201 model’s performance achieved an accuracy score of 98.93% on the validation dataset after 15 epochs. Furthermore, the final model’s performance achieved an accuracy score of 53.69% on the test dataset after 15 epochs.

CONCLUSION: In this iteration, the DenseNet201 CNN model did not appear suitable for modeling this dataset due to a high-variance problem. We should consider experimenting with more or different data for further modeling.

Dataset Used: Textile Defect Detection

Dataset ML Model: Multi-class image classification with numerical attributes

Dataset Reference: https://www.kaggle.com/belkhirnacim/textiledefectdetection

A potential source of performance benchmarks: https://www.kaggle.com/belkhirnacim/textiledefectdetection

The HTML formatted report can be found here on GitHub.

Algorithmic Trading Model for Trend-Following with APO 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 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 absolute price oscillator (APO) 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 loss has reached the established 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 an APO indicator with a range of plus and minus 2 to 4 dollars. Furthermore, we established a profit cap 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 an APO indicator with a range of plus and minus 2 to 4 dollars. Furthermore, we will establish a profit cap of 15% and a loss threshold of 8%.

ANALYSIS: From iteration Take1, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2018, and March 19, 2021. The top trading model produced a profit of 136.38 dollars per share. The buy-and-hold approach yielded a gain of 109.12 dollars per share.

In this Take2 iteration, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2018, and March 19, 2021. The top trading model produced a profit of 136.38 dollars per share. The buy-and-hold approach yielded a gain of 10.97 dollars per share.

CONCLUSION: For the stock of COST during the modeling time frame, the short-only 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.

Seth Godin’s Akimbo: Marginal Cost

In his Akimbo podcast, Seth Godin teaches us how to adopt a posture of possibility, change the culture, and choose to make a difference. Here are my takeaways from the episode.

In this podcast, Seth discusses the idea behind marginal cost and why it matters in our culture today.

Physical goods cost money to produce, and they have marginal costs. The marginal cost is the cost of making the last unit from the assembly line or manufacturing process. Many goods have low marginal costs once the assembly line can churn out those goods at scale. Like buildings and houses, some goods have high marginal costs because it is still difficult to produce them at scale.

We need to aware of the marginal cost because it affects how a provider makes their products and services available to us. The marginal cost concept also can affect an industry because technologies have fundamentally changed many industries. The decline in physical bookstores and book printing access on-demand is just two apparent patterns of change currently being experienced by the book industry.

Technologies can impact the marginal cost differently for a different audience, even in the same industry. Take the book industry as an example again. While the printed book’s marginal cost from the printing press may be low, the marginal cost for books printed-on-demand is still much higher than the one from the printing press. While books can go out-of-print with the printing press process, the same books will always be available for the print-on-demand route. Advance in technologies has given us more choices.

Things get interesting when we talk about books available in digital format. For digital books, the marginal cost approaches zero. This phenomenon has interesting implications for both the producer and consumer of the book. The same approaching-zero marginal costs scenarios are playing out for many products and services that may be available to use via digital format.

But what is even more interesting is when the marginal cost goes negative. When the marginal cost goes negative, each additional unit sold generates even more value for the producer. There are many examples of negative marginal costs in our digital world today.

The network effect has made negative marginal costs possible for many digital services. When something is benefiting from the network effect, it becomes more valuable as more people use it. The social network is one prime example of a network effect.

When a producer has goods or services that benefit from the network effect, they want to get more people involved with the goods or service. Those producers need the right people in the circle, or its product or service will not work. And they will create all sorts of incentives for people to join and not to leave.

When we are involved with a product or service defined by network effect, we should not be naïve to think that someone is doing us a favor by producing those products and services. We are doing them a favor by being in the circle because that is their business model’s essence.

This ultimately means that we are not the customers any more for those business models where the network effect is the foundation. We have become the product.

操作順序

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

如果你把果醬塗在花生醬之前,你做的三明治會是個失敗。

而且,如果您嘗試將花生醬塗在盤子上,然後再添加麵包,那三明治甚至會變得更糟糕。

像很多東西一樣,有些時候順序不是隨便可選的。

但是我們經常會首先去做成本最低或是最簡單的部分,無論操作順序告訴我們該如何去做。

NLP Model for IMDB Movie Sentiment Using TensorFlow Take 1

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

SUMMARY: This project aims to construct a text classification model using a neural network and document the end-to-end steps using a template. The IMDB Movie Sentiment dataset is a binary classification situation where we attempt to predict one of the two possible outcomes.

INTRODUCTION: This dataset contains 50,000 movie reviews extracted from IMDB. The researchers have annotated the tweets with labels (0 = negative, 1 = positive) to detect the reviews’ sentiment.

In this Take1 iteration, we will create a bag-of-words model to perform binary classification (positive or negative) for the Tweets. The Part A script will focus on building the model with the training and validation datasets due to memory capacity constraints. Part B will focus on testing the model with the training and test datasets.

ANALYSIS: In this Take1 iteration, the preliminary model’s performance achieved an average accuracy score of 88.80% after 25 epochs with ten iterations of cross-validation. Furthermore, the final model processed the test dataset with an accuracy measurement of 89.48%.

CONCLUSION: In this iteration, the bag-of-words TensorFlow model appeared to be suitable for modeling this dataset. We should consider experimenting with TensorFlow for further modeling.

Dataset Used: IMDB Movie Sentiment

Dataset ML Model: Binary class text classification with text-oriented features

Dataset Reference: https://www.kaggle.com/columbine/imdb-dataset-sentiment-analysis-in-csv-format

One potential source of performance benchmarks: https://www.kaggle.com/columbine/imdb-dataset-sentiment-analysis-in-csv-format

The HTML formatted report can be found here on GitHub.

Multi-Class Image Classification Deep Learning Model for Textile Defect Detection Using TensorFlow Take 1

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

SUMMARY: This project aims to construct a predictive model using a TensorFlow convolutional neural network (CNN) and document the end-to-end steps using a template. The Textile Defect Detection dataset is a multi-class classification situation where we attempt to predict one of several (more than two) possible outcomes.

INTRODUCTION: This dataset from Kaggle contains 96,000 patches of the textile image with different quality problems. The goal of the exercise is to detect the quality issue for a patch of textile during production. The greyscale photos are part of the public dataset made available by the MVTec Company and referred by the research paper from Paul Bergmann, Michael Fauser, David Sattlegger, Carsten Steger. MVTec AD – A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection; in: IEEE Conference on Computer Vision and Pattern Recognition (CVPR), June 2019.

In this Take1 iteration, we will construct a CNN model using a simple three-block VGG architecture and test the model’s performance using a separate test dataset.

ANALYSIS: In this Take1 iteration, the baseline model’s performance achieved an accuracy score of 97.07% on the validation dataset after 15 epochs. Furthermore, the final model’s performance achieved an accuracy score of 68.03% on the test dataset after 15 epochs.

CONCLUSION: In this iteration, the simple three-block VGG CNN model did not appear suitable for modeling this dataset due to a high-variance problem. We should consider experimenting with more or different data for further modeling.

Dataset Used: Textile Defect Detection

Dataset ML Model: Multi-class image classification with numerical attributes

Dataset Reference: https://www.kaggle.com/belkhirnacim/textiledefectdetection

A potential source of performance benchmarks: https://www.kaggle.com/belkhirnacim/textiledefectdetection

The HTML formatted report can be found here on GitHub.

Algorithmic Trading Model for Trend-Following with APO 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 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 absolute price oscillator (APO) 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 loss has reached the established 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 an APO indicator with a range of plus and minus 2 to 4 dollars. Furthermore, we will establish a profit cap of 15% and a loss threshold of 8%.

ANALYSIS: In this Take1 iteration, we analyzed the stock prices for Costco Wholesale (COST) between January 1, 2018, and March 19, 2021. The top trading model produced a profit of 136.38 dollars per share. The buy-and-hold approach yielded a gain of 109.12 dollars per share.

CONCLUSION: For the stock of COST during the modeling time frame, the long-only 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.