Skip to main content
  1. Blog/

Does Bitcoin correlate with the stock market?

This is a question I ask myself for quiet some time. An answer could be useful to build an effective prediction model, or to start some experiments with algorithmic trading. To answer this question I will build a simple script in Python using the Binance API and data from Google trends and yahoo finance. I would have liked to include data from Twitter too, but Twitter API only allows to gather data from the last 7 days.

First I gathered 3 months of data from various APIs und concatted it into one single dataframe. The result looked like this:

I dropped the row with the “Close” statements and Google keywords and prepared the data for correlation:

Log return is used, because the change of percentage can be summed up over time and this dataframe is made out of time series data.

Then I created a correlation matrix out of this:

Afterwards I visualized the correlation matrix with seaborn:

What do we learn from this? To be honest I thought the Bitcoin price would have a stronger correlation to the Google searches of the keyword “bitcoin”. Surprisingly the correlation between the Bitcoin price and the keyword “blockchain” is stronger than this. Bitcoin correlates the most with Nasdaq, S&P500 and the DowJones, which was not a huge surprise. It seems like there is a strong correlation between Bitcoin and US indices.

Next step would be to test rolling correlation, or if there is a lagged correlation, as the BTC price often needs some time to adjust to the market. When I get a chance, I’ll update this article with it.

Lars Ursprung
Author
Lars Ursprung