このサイトを参考にしながら、ドル円レートと日本のGDPには何かしらの相関関係があるのか調べてみることにした。もし相関関係があれば、何で先進国であるはずの日本が薄汚い為替操作国であるのかという理由にもなる。
ドル円レートGDPのグラフ化¶
from pandas import *
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.rcParams['figure.figsize'] = 20, 12
yen_dollar = 'DEXJPUS.csv'
jp_gdp = 'JPNNGDP.csv'
exchange = read_csv(yen_dollar)
jp_gdp = read_csv(jp_gdp)
new_table = pd.merge(jp_gdp,exchange)
new_table
new_table.columns = ['DATE','JPN_GDP','USD_JPY_EXCHANGE']
new_table.head()
new_table = DataFrame(new_table)
new_table.head()
jp_gdp_exch_scatt = new_table.plot('JPN_GDP','USD_JPY_EXCHANGE',grid=True, kind='scatter', s = 70)
jp_gdp_exch_scatt.set_title('Correlation between Japanese GDP and the Exchange Rate ', fontsize = 20)
jp_gdp_exch_scatt.set_xlabel('Japanese GDP (Billions of Yen)')
jp_gdp_exch_scatt.set_ylabel('Dollar-Yen Exchange Rate (Yen)')
jp_gdp_plot = new_table[['DATE','JPN_GDP']].set_index('DATE').plot()
jp_gdp_plot.set_title('Japanese GDP 1995 - 2018', fontsize =20)
jp_gdp_plot.set_ylabel('Japanese GDP (Billions of Yen)')
exchange_plot = new_table[['DATE','USD_JPY_EXCHANGE']].set_index('DATE').plot()
exchange_plot.set_title('Dollar Yen Exchange Rate 1995 - 2018', fontsize =20)
exchange_plot.set_ylabel('USD-JPY Exchange Rate (Yen)')
from matplotlib.pyplot import *
from matplotlib.font_manager import FontProperties
from matplotlib import rcParams
style.use('ggplot')
rcParams["font.size"] = "17"
fp = FontProperties(fname='/usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf', size=54)
rcParams['font.family'] = fp.get_name()
fig, ax = plt.subplots(figsize=(20,12))
new_table[['DATE','JPN_GDP']].set_index('DATE').plot(ax=ax,color="red")
ax.set_ylabel('GDP (10億円)')
ax.set_title('1995年〜2018のドル円レートとGDPの相関関係 ', fontsize =20)
ax.legend(["GDP"],loc='lower right', prop={'size': 26})
ax2 = ax.twinx()
new_table[['DATE','USD_JPY_EXCHANGE']].set_index('DATE').plot(ax=ax2,color="blue")
ax2.set_ylabel('ドル円レート (円)')
ax2.legend(["ドル円レート"],loc='lower left', prop={'size': 26})
ax2.annotate('リーマンショック', xy=(57,79), xycoords='data',
xytext=(-50, -20),textcoords='offset points',
size=25, ha='right', va="center",
bbox=dict(boxstyle="round", alpha=0.1),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1))
ax2.annotate('東日本大震災', xy=(64,79), xycoords='data',
xytext=(60,280),textcoords='offset points',
size=25, ha='right', va="center",
bbox=dict(boxstyle="round", alpha=0.1),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1))
ax2.annotate('異次元緩和', xy=(73,98.681094), xycoords='data',
xytext=(145, -100),textcoords='offset points',
size=25, ha='right', va="center",
bbox=dict(boxstyle="round", alpha=0.1),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1))
ax2.annotate('消費税増税', xy=(77,102.103906), xycoords='data',
xytext=(145, -60),textcoords='offset points',
size=25, ha='right', va="center",
bbox=dict(boxstyle="round", alpha=0.1),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1))
ax2.annotate('アジア通貨危機', xy=(10,120), xycoords='data',
xytext=(120, -200),textcoords='offset points',
size=25, ha='right', va="center",
bbox=dict(boxstyle="round", alpha=0.1),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1))
ax2.annotate('日米協調介入', xy=(14,140), xycoords='data',
xytext=(200, -5),textcoords='offset points',
size=25, ha='right', va="center",
bbox=dict(boxstyle="round", alpha=0.1),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1))
ax2.annotate('安倍政権誕生', xy=(71,81), xycoords='data',
xytext=(200, 5),textcoords='offset points',
size=25, ha='right', va="center",
bbox=dict(boxstyle="round", alpha=0.1),
arrowprops=dict(arrowstyle="wedge,tail_width=0.5", alpha=0.1));
ドル円レートとGDPに相関関係があることは確かだが、時期によってその事情は大いに異なる。奇しくも1997年の消費税増税後のジョージ・ソロスによるタイバーツの空売りで始まったアジア通貨危機時、拓銀・山一ショックと銀行連鎖破綻の恐怖が高まりにより、日本は平成大恐慌前夜にあった。それを救ったのが、政府による思い切った財政出動と銀行救済、日銀のゼロ金利政策だったことは記憶に新しいが、その後もアメリカのドットコムバブル崩壊、911テロにより日本経済は大いに苦しんだ。2003年が平成最悪の超氷河期だったのも納得できよう。この時期だけを見れば、行き過ぎた通貨安が経済に悪影響を与えることが見て取れるだろう。もちろん、基本的には円安時に総じてGDPが上昇傾向にあることも確かである。しかしながら、世界経済が減速傾向にある時は、円安であってもGDPが伸び悩んでいることも事実である。リーマンショック以降、円がスイスフラン並の安全通貨になったことと、アメリカの度重なる金融緩和による円高、さらに東日本大震災によるによりGDPがかなり伸び悩んだ。安倍政権誕生期待で一気に円安に傾き、マジキチ緩和の発動によりGDPはリーマンショック前の水準を取り戻している。しかし、実際は、アベノミクスが成功しているように見せるために、インチキ・粉飾・誤魔化し・水増しやりたい放題でGDPを思いっきり無理くりかさあげしまくっているという説もある。まぁ、令和元年終了時には日銀が500兆円国債買い取って、30兆円を株式市場にぶっ込んでいる事実を考えれば、これだけメチャクチャやってもインチキ粉飾しないとGDPが減る可能性があるという厳然たる事実を、全ての日本国民が真正面から受け止める必要がある。この国はもう完全に詰んでいるという事実を知る時に来ているということだ。
rと最小二乗法による推定係数¶
What is the relationship between these data sets? Are they even correlated?
これらのデータセットの関係は何なのか?本当に相関性があるのか?
The regression model is: y’ = a + bx
回帰モデルはy’ = a + bx
Where b is the slope and a is the intercept.
bが傾きでaが切片
Therefore: (Yen-Dollar Exchange) = a + b(Japan_GDP)
従って、ドル円レート = a + b(GDP)
jpn_gdp_Column = new_table['JPN_GDP']
exchange_Column = new_table['USD_JPY_EXCHANGE']
jpn_gdp_Column.describe()
exchange_Column.describe()
#Sum of X
jpn_gdp_Column.sum()
#Sum of Y
exchange_Column.sum()
#Sum of X times Y
x_y = jpn_gdp_Column*exchange_Column
x_y.sum()
#Sum of X squared
jpn_gdp_sq = jpn_gdp_Column**2
jpn_gdp_sq.sum()
#Sum of Y squared
exchange_sq = exchange_Column**2
exchange_sq.sum()
#Set variables
X = new_table.JPN_GDP
X = np.vstack(new_table.JPN_GDP)
Y = new_table.USD_JPY_EXCHANGE
Y = np.vstack(new_table.USD_JPY_EXCHANGE)
X = np.array([ [value,1] for value in X]).astype(np.float32)
#Use numpy Least Squares (lstsq) to find the Regression Coefficients
regression = np.linalg.lstsq(X,exchange_Column,rcond=-1)
regression
print('The slope is %.4f' %regression[0][0])
print('The y intercept is %.3f' %regression[0]3)
係数推定の正確度を評価する (Get Error)¶
#Get error
total_error = regression[1]
print('The total error was %.3f' %total_error[0])
#Get Root Mean Sqaure Error
rmse = np.sqrt(total_error/len(X))
print('The root mean squared error was %.2f' %rmse)
There’s a 95% chance that any given exchange rate in this time period will be within 2 times this error, or 21 yen away from the fit line.
この時間枠における任意の為替レートがこのエラーの2倍以内、もしくは、適合線から21円それる可能性が95%存在する。
回帰をプロットする¶
import scipy
from scipy import stats
from scipy.stats import t
#find t-statistic
r = 0.681
t = ((r)*np.sqrt((96-2)/(1-(r**2))))
print('The t-statistic is %.3f' %t)
from scipy.stats import t
#pass t statistic and degrees of freedom
#checked by hand
pvalue = t.sf(9.016, 2)
print('The p-value is %f' %pvalue)
m , b = scipy.linalg.lstsq(X,Y)[0]
#Plot centroid using X and Y means
plt.plot([520118.152083], [107.973519], marker='o', markersize=10, color="red")
#Plot best fit line
plt.plot(jpn_gdp_Column,exchange_Column,'o',color='green')
x = new_table.JPN_GDP
plt.plot(x, m*x + b, 'r')
plt.title('USD-JPY Exchange Rate and Japanese GDP Regression Line',fontsize=20)
plt.xlabel('Japanese GDP (Billions of Yen)')
plt.ylabel('USD-Yen Exchange Rate (Yen)');
2016年以降、ドル円レートに関係なくGDPがうなぎのぼりに伸びているのは、粉飾インチキ水増ししているからだろう。ある著名なエコノミストが、日本の実際のGDPはせいぜい500兆円程度だと言っていたが、その数字が最も真実に近い数字だと思われる。