Bitcoin and Tech Stocks: are they playing the same song? -Part 1

Topaccina
4 min readAug 3, 2022

--

How Bitcoin is positioned with respect to the stock market? Let’s build a clustering model for the market segmentation. Any similarities with Bitcoin? Powered by Python and open data.

Figure1: is Bitcoin moving together with the traditional stock market? image source- “The Cryptonomist”

It seems we are in the middle of a financial winter impacting both Crypto and Stock Markets. Bitcoin price declined breaking the psychological barrier of $20K. In this scenario it is quite challenging trying to define an efficient portfolio strategy.

Thinking of the Markovitz theory on the Efficient Frontier [1,2] aimed to maximize the portfolio returns for a given risk, the correlation between the assets is of great importance. There is no benefit in risk reduction by including mainly assets with similar trends.

Nowadays modern investors’ portfolios commonly includes, together with stocks, also a quote of crypto assets dominated by “The King Bitcoin” .

How is Bitcoin positioned with respect to the stock market? Is it uncorrelated or does it mimic certain assets more than others? How did the scenario change across the time? In the last few years Bitcoin is demonstrating resilience and starting to attract institutional investors.

Powered by Python and open data, let’s implement a “first-level analysis” to approach this complex matter.

This post is split in two parts:

Part 1 — Introduction to the context. Preliminary study of assets correlation with Bitcoin on a >5 years time frame.

Part2 — Assets segmentation with the support of unsupervised machine learning algorithms and wrap-up

What’s inside the “Phytonic magic” Toolbox:

Python 3.8 and above. Python packages: Pandas, Numpy, yfinance (to get prices from Yahoo API), Matplotlib, Seaborn, Plotly (for plots) [3,4]

import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objects as go

BitCoin vs Other assets: >5 years of correlation.

Inspired by a recent post from ChainAnalysis blog[5], I retrieved via Yahoo Python API more than 5 years of daily data for Bitcoin (BTC-USD), Gold (GC=F), US Treasury Bonds (TLT), Tesla (TSLA) , Microstrategy (MSTR) together with SP500 and Nasdaq indexes (The Python code idea here below)

#get Close price
for tck in tickerList:
print('retrieve '+tck)
df_temp=yf.download(tck, start='2016-06-15', \
end='2022-06-15', \
period='1d',progress=False)
df['%s'%(tck)]=df_temp['Close']

MSTR and TLT can be considered as our benchmarks. It is expected to see low BTC- bond correlation whereas a certain assonance between BTC and Microstrategy, that are “well-known double stranded”.

Let’s proceed then with data cleansing and feature engineering steps to evaluate rolling correlation between BTC and the selected assets. Line chart in Figure 2 showing the correlations vs time (The Python code idea here below).

#eval BTC vs other stocks rolling correlation
for tck in tickerList:
df_temp=df['BTC-USD'].rolling(15).corr(df['%s'%(tck)])
...
..
#smooth the results
for tck in tickerList:
df_corr[tck+'_MAV']=df_corr[tck].rolling(100).mean()
...
Figure 2: more than 5 years rolling correlation of BTC vs a subset of assets selected from different sectors.

Until the 2020 for all the assets there is no clear correlation. It is like a “stationary process”, but starting from 2020 something has changed. Microstrategy is the first to emerge showing a positive trend. This is expected and supported by the chronicles of that period (Fig2)[6]

Figure 3: https://www.microstrategy.com/en/company/company-videos/microstrategy-announces-over-1b-in-total-bitcoin-purchases-in-2020

Interesting to note that a delayed trend is coming to reveal starting from 2021 on TSLA but also on SP500 and Nasdaq. Gold and Bonds still remain uncorrelated.

Data heatmaps could help for cross-examining these multivariate data. In the last year Bitcoin price movements seem more aligned with tech-companies stocks from this small dataset

igure 4: heatmap of 5 years rolling correlation of BTC vs a subset of assets selected from different sectors. Higher and more stable correlation (>0.6) popped up after 2020 for tech

It would be curious to investigate what is the profile of the average Bitcoin investor in 2022. Does it match with the “growth investors” traditionally oriented to promising innovative industries?

Implementing a stocks segmentation accordingly with their correlation with Bitcoin could provide some hints. The SP500 index includes companies from more than 10 sectors. It could be a good starting point to check if there are identifiable patterns based on the sector.

❤️‍🔥❤️‍🔥To be continued…see you in Part2 ❤️‍🔥❤️‍🔥

References:

[1] https://en.wikipedia.org/wiki/Markowitz_model

[2] https://en.wikipedia.org/wiki/Efficient_frontier

[3]https://plotly.com/graphing-libraries/

[4] https://pypi.org/project/yfinance/

[5]https://blog.chainalysis.com/reports/how-terrausd-collapsed/

[6] https://www.microstrategy.com/en/company/company-videos/microstrategy-over-1b-in-total-bitcoin-purchases-in-2020

[7] https://medium.com/@laulor1981/bitcoin-and-tech-stocks-are-they-playing-the-same-song-part-2-bee2565c84ea

--

--

Topaccina

Interested in Data science, ML, AI & blockchain! 💕 -Data analyst, semiconductors industry. Runner for fun! linkedin.com/in/laura-lorenzi-14885a12