Correlation between economic indicator and exchange rate/stock price
%matplotlib inline
import pandas as pd
import seaborn as sns
Convert Excel file @ vdata.Nikkei.com into DataFrame
- 日経新聞社 掲載指標ダッシュボード
Nikkei.com Economic Dashboard
# Real Gross Domestic Product
try:
gdp = pd.read_excel('https://vdata-stats-data.s3.amazonaws.com/xls/NA04Q.xls', index_col=0)
except Exception:
gdp = pd.read_excel('data/NA04Q.xls', index_col=0)
# Diffusion Index
try:
di = pd.read_excel('https://vdata-stats-data.s3.amazonaws.com/xls/NA21M.xls', index_col=0)
except Exception:
di = pd.read_excel('data/NA21M.xls', index_col=0)
# Nikkei index
try:
n225 = pd.read_excel('https://vdata-stats-data.s3.amazonaws.com/xls/NE51M.xls', index_col=0)
except Exception:
n225 = pd.read_excel('data/NE51M.xls', index_col=0)
# USD/JPY
try:
usd_jpy = pd.read_excel('https://vdata-stats-data.s3.amazonaws.com/xls/NE11M.xls', index_col=0)
except Exception:
usd_jpy = pd.read_excel('data/NE11M.xls', index_col=0)
merge each DataFrames into one DataFrame
# Add "axis=1" to merge in horizontal direction
df = pd.concat([gdp.iloc[:, 0], di.iloc[:, 0], n225.iloc[:, 0], usd_jpy.iloc[:, 0]], axis=1)
df.columns = ['GDP', 'DI', 'n225', 'USD/JPY']
# remove nan value
df.dropna(inplace=True)
visualize by seaborn
sns.pairplot(df)
<seaborn.axisgrid.PairGrid at 0x7fbe7bafb1d0>
correlations
df.corr()
GDP | DI | n225 | USD/JPY | |
---|---|---|---|---|
GDP | 1.000000 | 0.574783 | 0.773079 | 0.771475 |
DI | 0.574783 | 1.000000 | 0.380856 | 0.303481 |
n225 | 0.773079 | 0.380856 | 1.000000 | 0.985945 |
USD/JPY | 0.771475 | 0.303481 | 0.985945 | 1.000000 |