An Exploratory Data Analysis On The Relationship Between Gold And Bitcoin

By Hayden Poore on ALTCOIN MAGAZINE

Hayden Poore
Published in
5 min readOct 29, 2019

--

The question of whether to buy Bitcoin or to buy Gold has been an interesting debate for traders in the past few years. These are two very different markets with Bitcoin being a peer-to-peer decentralized digital currency first created in 2009 while Gold a very much tangible asset has been highly valued since the beginning of human civilization. Both of these options now serve as a utility of currency with Gold being the safer option because of its low volatility. Satoshi Nakamoto envisioned bitcoin as a kind of digital gold and now bitcoin is seen as a competitor to gold. Both Gold and Bitcoin have little correlation with other asset classes but with Bitcoin being more volatile there is a larger potential profit opportunity.

With the rise in popularity of bitcoin, I decided to see if there was a relationship between the price of these two assets.

I found a very complete data set on Kaggle covering the price of bitcoin every minute from 2014 to 2018 that was made from a popular bitcoin exchange called CoinBase. The kaggle user Zielak was able to obtain this data from various exchange API’s listed in Unix time.

Bitcoin Historical Price Data Frame

The first thing I noticed after reading in the data is that there is a timestamp object in Unix that needs to be converted to a date-time object and a whole lot of missing data. I used the pandas drop NA function to better clean my data and the date-time module from Python to convert the Unix to a human-readable date-time object.

Here is a snippet of the updated data frame with converted dates and dropped NA values.

Updated Data Frame

My next step was to read in and clean my historical gold price data. For this analysis, I decided to only use the close data because that most accurately represents the price for that day.

Gold Price Data Frame

The date column is currently a string that doesn’t match the format of the bitcoin dates. So I again used the Python Date Time module to convert it into a date-time object.

Fixed Dates

My next step was to combine the data frames and begin my analysis. There was one problem though. The bitcoin data from CoinBase had data from each minute of every day from 2014 to 2018 while the gold data only had prices for every day.

I decided the best way to go about this was to group each data point from the bitcoin data frame into its corresponding date. I trimmed the hour, seconds and milliseconds off the date column.

Trimmed Dates on BTC data

But now there are hundreds of data points for each day. Performing a simple group by average, by the date I was able to derive a daily average.

BTC average price by day

The next step was to combine the two data frames in order to begin an analysis. I used pandas’ merge function with an inner join so that my new data frame only contained data from each data set.

Code to combine data frames
Resulting data frame

Now I could begin my analysis and I did so by making visualizations showing the change in price over the date range.

Bitcoin Price Graph
Gold Price Graph

I then wanted to create a single graph to see the correlation between prices but that proved to be unsuccessful as the range of prices between the two differ greatly.

Graph of Bitcoin and Gold Price

This graph tells us nothing so I decided to take another route for my analysis.

I decided to look and see if a gold price increase would result in a bitcoin price increase and vice versa. Using some loops to iterate through my data frame I was able to calculate the number of times both prices increased, both prices decreased or price change was inverted between the two per day.

Code to calculate relationship of price changes

With this code I was able to find the number of times that both prices increased, both prices decreased and the number of times that one increased while the other decreased.

Now that I had these calculations it was time to visualize it.

Relationship of Price Changes Between Bitcoin and Gold

Of the 991 days that I had data for 49% of the time, there was an inverse relationship between the price changes of Bitcoin and Gold. One reason that I think that these two have an inverse relationship is that the price change in one affects trader behavior regarding the other. An active trader may see that the price of bitcoin is decreasing so they decide to purchase gold and vice versa.

Looking forward to an analyst’s perspective I feel like doing a similar analysis but also looking at the NASDAQ or NYSE and see if the stock market has a similar relationship in the relationship to the price of gold or the price of bitcoin.

--

--

Hayden Poore
The Dark Side

Information and Data Science Student with a minor in Business Analytics at the University of Colorado Boulder. Currently seeking a Summer 19 Internship.