Day & Month Performance Heatmap — Stock Data Analysis

Market Ahead
6 min readJan 16, 2019

Timing trades can be difficult especially if you have a tight deadline or if you’re just casually trading on apps like Robinhood. As much as I’ve heard of “buy on Mondays and sell on Fridays”, I’ve never been able to follow it. Sometimes I wish there was a general rule of thumb for a given stock. It’d skim some of the emotion out while perhaps giving a slight advantage by trading based on how the stock has historically moved.

The “buy on Mondays and sell on Fridays” comes from various factors including the the average % change. The higher the average % change for the given day (or month) the better it is to sell and vice versa. Looking at the charts below, historically, for the S&P500 the best day to buy in 2018 was Thursday and the best day to sell was Friday. From 1950–2017, the best month to buy was September and to sell was December.

S&P 500 % Change by Weekday and Month

From Investopedia.com: “These suggestions as to the best time of day to trade stocks, the best day of week to buy or sell stocks, and the best month to buy or sell stocks are generalizations, of course. Exceptions and anomalies abound, depending on news events and changing market conditions. The closest thing to a hard and fast rule is that the first and last hour of a trading day are the busiest, offering the most opportunities — but even so, many traders are profitable in the off-times, as well.”

With the understanding that these are simply generalizations, wouldn’t it still be nice to get a general gist of how a stock historically performed on a given day of the week and month?

For this project, I used AlphaVantage’s API and MongoDB Chart’s built-in heat map feature. Information on a heatmap can be read at a glance making it easy to see how a stock’s price performs historically for a given day of the week and month. For starters, I plotted the average percent closes as intensities across the months and days of the week where green denotes a higher average close % and red denotes a lower average close %. For this example, I’ll use Intel (INTC). AlphaVantage has data since 1998, so not its full history.

INTC Day and Month Performance Heatmap v1

Let’s say it’s January, the best performing day would be Monday and the least would be Friday. Moreover, in July, Thursday would historically perform better than Friday. In general, the days of the week should be looked at for each corresponding month independently, where darker shades indicate a larger +- average closing percentage and lighter shaded colors means the closing percent averages are closer to zero.

To better differentiate the shades, I removed daily percentage changes +-1% without losing much information and enhanced the differentiation between squares.

INTC Day and Month Performance Heatmap v2

While this works to give a general idea of the percent change for a given day of the month, it failed to given any indication of which month had the best average return. Historically, Intel has the best average monthly returns in October and the worst in September.

INTC Average Monthly Returns

To add this data into the heatmap, I took the average monthly returns (normalized) and added it as a weight to the respective monthly closing averages. Now the heatmap could not only tell how each day of the month performed but also how each month compares with each other.

INTC Day and Month Performance Heatmap v3

It’s now more clear from the revised heatmap that October and November are well performing months (generally green squares) and September is the worst performing (denoted by the abundance of darker red squares). Note that the color bar is now shifted with the monthly data weight so I’ve removed it.

I also examined differences between bull and bear cycle heatmaps. There exhibits some differences between both heatmaps and during a bear market there were notably more differences to our original heatmap above. This could be due to bear markets having less data points. 20 years of data only means two recessionary bear cycles so I still prefer to use the overall average without taking different periods into account. I may revisit this if I can get access to more complete datasets.

Heatmap during Bull Market vs. Bear Market

In conclusion, A LOT of things can be improved such as better heatmap intensties, annotations, and giving a definitive color step rather than having to rely on reading from color gradients which are sometimes hard to differentiate. The lack of full data set from AlpahVantage and limited abilities in MongoDB charts also makes it hard to further expand on these heatmaps without re-writing the code from scratch and directly using Matlibplot which I’ll save for a future project.

All-in-all, the Day and Month Performance Heatmap provides a quick overview of the average historic performance across days and months for a given stock whether it is useful or not is another question. Using in conjunction with TA and other tools may also further improve decision making especially if you are on a tight timeline; however, at the end of the day it’s still simply a generalization and can only be taken with a grain of salt.

A few other Day and Month Performance Heatmaps for reference:

AMD Day and Month Performance Heatmap
BABA Day and Month Performance Heatmap
BIDU Day and Month Performance Heatmap
CHL Day and Month Performance Heatmap
CY Day and Month Performance Heatmap
FB Day and Month Performance Heatmap
GOOGL Day and Month Performance Heatmap
MRAM Day and Month Performance Heatmap
MU Day and Month Performance Heatmap
NLST Day and Month Performance Heatmap
SHOP Day and Month Performance Heatmap
SQ Day and Month Performance Heatmap
TCEHY Day and Month Performance Heatmap
TSLA Day and Month Performance Heatmap
WDC Day and Month Performance Heatmap
XLNX Day and Month Performance Heatmap
ZTO Day and Month Performance Heatmap
SPY Day and Month Performance Heatmap
GLD Day and Month Performance Heatmap

--

--

Market Ahead

For every action, there is an equal and opposite reaction.