Best Day of the Week to Buy a stock

Background

When people start trading stocks they always want to find an edge and I am no different. However, most trading applications that people create favor day trading. I wanted to create an app that gives investors who subscribe to the strategy of dollar-cost averaging (DCA) a leg up. So, if you saw the headline and were hoping this was a get-rich-quick app, I am sorry to inform you it is not.

What was the problem?

I am someone who enjoys picking a solid group of companies and just investing in their stocks on a weekly basis. When I first started I would just set automatic investments on Monday, because that was the first trading day of the week. However, I wondered if there was a better to buy. What if certain stocks on average traded higher. I would want to avoid those. Even if these differences were only a couple of percentage points on a large enough portfolio that could result in dramatic difference over time.

What technologies were used?

  • JavaScript (ES6)

  • Google App Script

  • Google Sheets

  • Twilio Programmable SMS

  • Google Finance API

How did I execute?

Bundlings the Weeks

The toughest part of the project was bundling the data into a week. A trading week is not simply 5 days, instead, it is Monday thru Friday. However, not all trading weeks start on a Monday or end on a Friday. There are holidays that cause the market to be closed so my calculations needed to account for that.

The way I did this was by iterating through the data and creating what I called bundles. Every iteration I would “check” the bundle to make sure:

  1. It did not contain duplicate days of the week. This would signal that the bundle was spanning over two weeks.

  2. It did not contain duplicate Fridays, again signaling the bundle was spanning two weeks.

If the bundle met either of these two conditions I would add it to a nested array that included all of the other bundled weeks.

Determining Best Day of the Week

After getting all of the weeks bundled together I then went through each day of the week to determine which day had the highest and lowest returns. The day with the best returns would be the best day to buy and the day with the worst returns would be the best day of the week to sell. The reason the day with the lowest return is the best day to sell is when you are buying on a weekly basis the day with the worst return would be the day of the week that was most expensive to purchase shares.