Created
August 17, 2017 16:57
-
-
Save fredfortier/493b393a97a1f05aee524b031687acbf to your computer and use it in GitHub Desktop.
Correlating the Rise of NEO (crypto) with Google Trends Interest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pytrends.request import TrendReq | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
import urllib.request, json | |
from dateutil.relativedelta import relativedelta | |
USERNAME = '' | |
PASSWORD = '' | |
pytrend = TrendReq(USERNAME, PASSWORD, hl='en-US', tz=360, | |
custom_useragent=None) | |
key = 'neo cryptocurrency' | |
pytrend.build_payload(kw_list=[key], timeframe='today 1-m', ) | |
df_interest = pytrend.interest_over_time() | |
print(df_interest.head()) | |
url = 'https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=BTC-NEO&tickInterval=day&_=1499127220008' | |
with urllib.request.urlopen(url) as url: | |
data = json.loads(url.read().decode()) | |
result = data['result'] | |
ohlc_df = pd.DataFrame(result) | |
ohlc_df['T'] = pd.to_datetime(ohlc_df['T']) | |
ohlc_df.set_index('T', drop=True, inplace=True) | |
start = pd.to_datetime('today') - relativedelta(months=1) | |
ohlc_df = ohlc_df.loc[start:] | |
print(ohlc_df.head()) | |
max_close = ohlc_df['C'].max() | |
perc_close = ohlc_df['C'] / max_close * 100 | |
df = pd.concat([df_interest, perc_close], axis=1) | |
interest, = plt.plot(df.index, df[key], '-', | |
color='blue', | |
linewidth=1.0, | |
label='Interests', | |
) | |
price, = plt.plot(df.index, df['C'], '-', | |
color='green', | |
linewidth=1.0, | |
label='Price' | |
) | |
plt.legend(handles=[interest, price]) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beautifulsoup4==4.6.0 | |
certifi==2017.7.27.1 | |
chardet==3.0.4 | |
cycler==0.10.0 | |
idna==2.6 | |
lxml==3.8.0 | |
matplotlib==2.0.2 | |
numpy==1.13.1 | |
pandas==0.20.3 | |
pyparsing==2.2.0 | |
python-dateutil==2.6.1 | |
pytrends==4.1.1 | |
pytz==2017.2 | |
requests==2.18.4 | |
six==1.10.0 | |
urllib3==1.22 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment