Financial “Magic”: Bitcoin and Magical Machine Learning Analysis

Posted by

·

We’ve all grown up seeing magic tricks! Whether it was a magician pulling a rabbit from a hat or somehow knowing exactly which card we picked, as kids we were filled with awe, but as adults, we come to understand the trick: things are rarely what they seem. Gaining insight often comes with age, and along with it come new challenges, especially around finances. Today, one of the most buzzed-about financial phenomena is Bitcoin. Is Bitcoin another trick waiting to be unmasked, or is there more behind the curtain? To tackle this question, I decided to dive back into VS Code and see what I could uncover.

The Top Hat: Regression Modeling

I kicked off my research with regression analysis—a statistical process that helps determine the correlation between a dependent variable (in this case, Bitcoin) and various independent variables. By selecting appropriate explanatory factors, I hoped to identify some fundamental patterns that might help predict Bitcoin’s movement. After some thought, I chose two indicators: the price of Gold and U.S. 10-Year Treasury Bond rates. I also applied a Random Forest Regression, a machine learning method that leverages decision trees on subsets of the dataset to produce predictive outcomes.

Bitcoin and other cryptocurrencies are celebrated as free-market assets, untethered to traditional economic policy. Yet, U.S. interest rates impact nearly every corner of the economy, so it stands to reason that Bitcoin might be influenced by these rates as well. The U.S. economy accounts for about 20% of the global economy, and its trends should theoretically impact Bitcoin’s value. Gold, on the other hand, has long been viewed as a financial safe haven, so I hypothesized that it might act as a substitute for Bitcoin—if gold’s price dropped, I expected Bitcoin’s price might rise. With these variables in hand, I set out to see if Bitcoin’s “magic” could be explained.

Preparing the Trick: Data Collection and Initial Analysis

For this analysis, I gathered data from Yahoo Finance, using the period from September 4, 2018, to September 4, 2024. After filtering for active trading days and removing unnecessary columns, I was ready to start. My first step was to check the correlation between the indicators. Understanding these relationships can give insight into how both indicators have moved in the past—whether they typically move together or in opposition. The heatmap below, generated with Python’s Seaborn library, illustrates these correlations:

Correlation Heatmap: Bitcoin Price v Gold Price v 10 Year Treasury Bond

To my surprise, the heatmap initially contradicted my expectations. Both Gold and 10-Year Treasury Rates (10YTR) had a strong positive correlation with Bitcoin, suggesting that interest rates indeed have a significant relationship with Bitcoin, but gold prices do not act as a substitute—instead, they are complementary. I’ll revisit this point later in the discussion.

Is this your card? Machine Learning Model Results.

With correlations established, I shifted to regression. Splitting my data into a training set (80%) and a testing set (20%), I trained the model and used Random Forest Regression to predict outcomes based on my indicators. The results were compelling:

Actual Bitcoin Price v Random Forest Regression Predictions

The model aligned closely with the actual data, suggesting that the Machine Learning model successfully captured Bitcoin’s behavior based on Gold and Interest Rates. The R-squared score of 0.959 further affirmed the model’s accuracy.

The Reveal: Takeaways and Reflections

This analysis is a basic approach but highlights some interesting insights. First, the positive correlation between Bitcoin and interest rates suggests that rising rates might trigger a secondary effect: decreased consumer purchasing power. Generally, as interest rates rise, consumers are likelier to invest in Treasury bonds, driving their prices up. This behavior might also prompt investment in alternative assets, like Bitcoin. Alternatively, in a high-interest-rate environment, a slowing economy could lead investors to view Bitcoin as a potential hedge against declining stocks—a worthy topic for further research.

Similarly, the positive correlation between Gold and Bitcoin might reflect both assets’ roles as perceived financial safeguards. Rather than being direct substitutes, they might attract parallel interest as economic conditions change, with consumers potentially viewing them as complementary hedges rather than alternatives.

It’s worth noting, however, that this analysis is fairly basic. Certain factors—such as omitted indicators—could introduce biases. For instance, stock prices might influence the correlations, which a future, more detailed analysis could address. Machine learning models are powerful but not flawless, and I look forward to exploring these dynamics further, hopefully with your insights and feedback. This was a very quick analysis, but maybe together, step by step, we can unmask more of the “magic” of Bitcoin and the financial world.


If you would like see more content like this be sure to subscribe to my blog and check out the Python Code below!

Analysis Code

Ahmed Saqer Avatar

About the author