Month: April 2020

（從我一個尊敬的作家，賽斯·高汀

# 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.

# Time Series Model for Female Births in California 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 California Female Births dataset is a time series situation where we are trying to forecast future outcomes based on past data points.

Additional Notes: This is a replication, with some small modifications, of Dr. Jason Brownlee’s blog post, How to Grid Search Triple Exponential Smoothing for Time Series Forecasting in Python (https://machinelearningmastery.com/how-to-grid-search-triple-exponential-smoothing-for-time-series-forecasting-in-python/). I plan to leverage Dr. Brownlee’s exponential smoothing or ETS (Error, Trend and Seasonality) tutorial examples and build an ETS-based notebook template for future uses.

INTRODUCTION: The problem is to forecast the daily number of female births in California. The dataset described a time-series of baby births over 12 months in 1959, and there are 365 observations. We used the first 200 observations for training the model while using the remaining 165 observations for validating the model.

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

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

Dataset Used: Daily total female births in California, 1959

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 “Buy Low Sell High” Using Python Take 2

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 this Take2 iteration, we will construct and test the trading model for the stock “GOOG” during the year of 2018.

ANALYSIS: 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%.

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 approach turned out to be a better choice again.

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.