# Start writing code here...
# Import modules for API calls
import requests
import io
import pandas as pd
import requests
import json
from datetime import datetime
import numpy as np
# Import module for plotting
import seaborn as sns
# interactive visualization
import plotly.express as px
import plotly.graph_objs as go
## JHU Vaccination Rates (Taken From: https://github.com/owid/covid-19-data/tree/master/public/data)
url = 'https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/owid-covid-data.csv'
download = requests.get(url).content
covid = pd.read_csv(io.StringIO(download.decode('utf-8')), parse_dates=['date'])
covid_US = covid[covid["location"]=="United States"]
covid_US
!pip install yfinance==0.1.63
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import datetime as dt
import yfinance as yf
# find the symbol (i.e., google the instrument + 'yahoo finance') to any data series you are interested at
# e.g., market/sector index ETF for your chosen country and various asset classes (e.g., Comex Gold's symbol is 'GC=F')
# e.g., SPY (https://finance.yahoo.com/quote/SPY/)
#Medical and health ETF, Zoom (remote working), Paypal (digital wallet), Bitcoin (digital currency), US bond, Bilibili (Video App)
symbols_list = ['PYPL', 'VHT','BTC-USD', 'GOOG', 'ZM', 'SPY', 'FB', 'AMZN']
start = dt.datetime(2020,3,1)
end = dt.datetime(2021,9,1)
data = yf.download(symbols_list, start=start, end=end)
mobility = pd.read_csv('Global_Mobility_Report.csv')
mobility = mobility[mobility["country_region"]=="United States"]
mobility['date'] = mobility.date.astype('datetime64')
# filter column adjusted close
# do not use close price as the price might be discountinous due to corporate actions
df = data['Adj Close']
# Unique names (e.g., crypto trade on weekends as well but stock do not)
df = df.ffill()
df.head()
df.reset_index(inplace=True)
df = df.rename(columns={"Date": "date"})
covid_US.columns
correlation = df.merge(covid_US[["date","excess_mortality", "hospital_beds_per_thousand", "new_cases_per_million", "people_vaccinated_per_hundred",]], how = "inner", on = "date")
correlation_new = correlation.merge(mobility[['date','retail_and_recreation_percent_change_from_baseline',
'grocery_and_pharmacy_percent_change_from_baseline',
'parks_percent_change_from_baseline',
'transit_stations_percent_change_from_baseline',
'workplaces_percent_change_from_baseline',
'residential_percent_change_from_baseline']],how = "inner", on = "date")
correlation_new.head()
correlation_new.replace('', np.nan).fillna(0)
corr_ = correlation_new.corr()
fig, ax = plt.subplots(figsize=(16,5))
sns.heatmap(corr_, annot=True, ax = ax)