Analyzing Cryptocurrency Trends: Comparing Bitcoin Price and Google Search Data

Apr 12, 2023

3 min read


programmer-with-chrome

Import pandas and matplotlib


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

install pytrends and import


!pip install pytrends

from pytrends.request import TrendReq
pytrends = TrendReq(hl='en-US', tz=360)
pytrends.suggestions(keyword='bitcoin')



result from pytrends


[{'mid': '/m/05p0rrx', 'title': 'Bitcoin', 'type': 'Cryptocurrency'},
     {'mid': '/g/11fzz0b6bd',
      'title': 'The Bitcoin Standard: The Decentralized Alternative to Central Banking',
      'type': 'Book by Saifedean Ammous'},
     {'mid': '/g/11g24jzg8x',
      'title': 'Cryptocurrency Investing For Dummies',
      'type': 'Book by Kiana Danial'},
     {'mid': '/g/11fx8y_lzq',
      'title': 'Mastering Bitcoin: Programming the Open Blockchain',
      'type': 'Book by Andreas Antonopoulos'},
     {'mid': '/g/11h2fx5fh8',
      'title': 'Bitcoin: A Peer-to-Peer Electronic Cash System',
      'type': 'Book by Satoshi Nakamoto'}]

# we must work use one by one keyword search google trend
kw_1 = ['bitcoin'] 
cat = 0
geo = ''
timeframe = '2020-01-01 2023-01-01'

pytrends.build_payload(kw_1, cat=cat, timeframe=timeframe, geo=geo, gprop='')
data = pytrends.interest_over_time()
# use interest over time


app = pytrends.interest_by_region(resolution='COUNTRY')
app

we will see data like this


bitcoin
geoName
Afghanistan0
Albania0
Algeria0
American Samoa0
Andorra0
Western Sahara0
Yemen0
Zambia0
Zimbabwe0
Åland Islands0

250 rows × 1 columns


try to plot chart


%matplotlib inline

data.plot(figsize = (12,6))

BTC-Trend


let try compare with btc price


import yfinance as yf
price = yf.download('BTC-USD', start='2020-01-01', end='2023-01-01')

[*****************100%*******************] 1 of 1 completed


price
OpenHighLowCloseAdj CloseVolume
Date
2020-01-017194.8920907254.3305667174.9443367200.1743167200.17431618565664997
2020-01-027202.5512707212.1552736935.2700206985.4702156985.47021520802083465
2020-01-036984.4287117413.7153326914.9960947344.8842777344.88427728111481032
2020-01-047345.3754887427.3857427309.5141607410.6567387410.65673818444271275
2020-01-057410.4516607544.4970707400.5356457411.3173837411.31738319725074095
2022-12-2716919.29101616959.84570316642.07226616717.17382816717.17382815748580239
2022-12-2816716.40039116768.16992216497.55664116552.57226616552.57226617005713920
2022-12-2916552.32226616651.75585916508.68359416642.34179716642.34179714472237479
2022-12-3016641.33007816643.42773416408.47460916602.58593816602.58593815929162910
2022-12-3116603.67382816628.98632816517.51953116547.49609416547.49609411239186456

1096 rows × 6 columns


Clean data


# match day with google trend 
df =price.resample('W',origin='2020-01-05').last()
datax = data.drop('isPartial', axis=1)

Plot Chart


fig, ax1 = plt.subplots(figsize = (12,6))
ax1.plot(price['Close'], label='BTC-USD')
ax1.set_xlabel('Date')
ax1.set_ylabel('BTC-USD Price')
ax1.legend(loc = 'upper left', labels=['BTC-USD Price'])

ax2 = ax1.twinx()
ax2.plot(datax, 'r', label='Google Trends')
ax2.set_ylabel('Google Trends')
ax2.legend(loc = 'upper right', labels=['Google Trends'])

plt.show()

png


Note


We will see in 2022-01 Google Trend indicator is less more than 2021-01 , 2021-05 maybe it mean people not interesting and price is over natural or retail is not interesting maybe it mean this is bear market signal


By the way, it may be used in a variety of hypotheses and can be improved depending on the idea.




try to filter only 2022-2023


start_date = '2022-01-01'
end_date = '2023-01-01'

price_filtered = price.loc[start_date:end_date]
price_filtered
OpenHighLowCloseAdj CloseVolume
Date
2022-01-0146311.74609447827.31250046288.48437547686.81250047686.81250024582667004
2022-01-0247680.92578147881.40625046856.93750047345.21875047345.21875027951569547
2022-01-0347343.54296947510.72656245835.96484446458.11718846458.11718833071628362
2022-01-0446458.85156247406.54687545752.46484445897.57421945897.57421942494677905
2022-01-0545899.35937546929.04687542798.22265643569.00390643569.00390636851084859
2022-12-2716919.29101616959.84570316642.07226616717.17382816717.17382815748580239
2022-12-2816716.40039116768.16992216497.55664116552.57226616552.57226617005713920
2022-12-2916552.32226616651.75585916508.68359416642.34179716642.34179714472237479
2022-12-3016641.33007816643.42773416408.47460916602.58593816602.58593815929162910
2022-12-3116603.67382816628.98632816517.51953116547.49609416547.49609411239186456

365 rows × 6 columns


fig, ax1 = plt.subplots(figsize = (12,6))
ax1.plot(price_filtered['Close'], label='BTC-USD')
ax1.set_xlabel('Date')
ax1.set_ylabel('BTC-USD Price')
ax1.legend(loc = 'upper left', labels=['BTC-USD Price'])

ax2 = ax1.twinx()
ax2.plot(daily.bitcoin, 'r', label='Google Trends')
ax2.set_ylabel('Google Trends')
ax2.legend(loc = 'upper right', labels=['Google Trends'])

plt.show()

png-2022-2023


Conclusion


Overall The idea of comparing Google Trends data with Bitcoin (BTC) price is to monitor the public’s interest and sentiment towards the cryptocurrency. Google Trends is a free tool that shows how often specific search terms are entered into Google search over a certain time period. By tracking searches related to Bitcoin, you can gauge the attention it receives from the general public.


To compare the two sets of data, plot them on a line graph with the BTC price on the y-axis and Google Trends data on the x-axis. Visually examining the graph can reveal patterns or correlations between the data.


However, keep in mind that correlation does not imply causation. A relationship between BTC price and Google Trends data doesn’t mean one causes the other. Other factors can drive changes in BTC price, such as regulatory developments, news events, or shifts in market sentiment.


Additionally, Google Trends data can be noisy and subject to manipulation. People or groups might inflate search volume for a term to create a false impression of interest. Also, searches can be misinterpreted or misreported. It’s important to be cautious and consider the data’s limitations when interpreting it.