前回は、fbprophetが予測したグーグルと帝人の株価をmatplotlibでグラフ化しましたが、今回は、prophetが予測した一年後の任天堂の株価をplotlyを使ってグラフ化して視覚効果を飛躍的に高めてみたいと思います。
from __future__ import division
import pandas as pd
import numpy as np
from datetime import datetime
from pandas import Series,DataFrame
import pandas_datareader as web
import fbprophet
from fbprophet.plot import plot_plotly
from plotly.offline import plot,iplot
import matplotlib.pyplot as plt
%matplotlib inline
df = web.DataReader('7974.JP','stooq')
df.head()
df.tail()
df = df.reset_index()
df[['ds','y']] = df[['Date' ,'Close']]
df = df[['ds','y']]
df.head()
スポンサーリンク
prophetで任天堂株価予測¶
m = fbprophet.Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
future.tail()
forecast = m.predict(future)
forecast.tail()
fig = plot_plotly(m, forecast) # This returns a plotly Figure
layout = dict(title = '任天堂株価予測',
title_font=dict(size=24, family='Courier', color='black'),
yaxis=dict(title='株価',title_font=dict(size=22)
,tickfont=dict(size=20)),
xaxis=dict(title='年',title_font=dict(size=22),tickfont=dict(size=20)),
autosize=False,width=800, height=640,
hovermode= 'x',
hoverlabel=dict(font=dict(size=24)),
legend=dict(x=-.001,y=1,font=dict(size=21,color='black'),bgcolor='rgba(0,0,0,0)'),
legend_orientation="v"
)
fig.layout.update(layout)
plot(fig,show_link=False,filename="stock_price_nintendo.html",include_plotlyjs=False)
任天堂株は来年は下降局面に入ることが予想されています。
スポンサーリンク
任天堂ADR株価データの準備¶
end = datetime.now()
start = datetime(end.year - 40,end.month,end.day)
df1 = web.DataReader('NTDOY','yahoo',start,end)['Adj Close']
df1.head()
df1 = df1.reset_index()
df1[['ds','y']] = df1[['Date' ,'Adj Close']]
df1 = df1[['ds','y']]
df1.head()
スポンサーリンク
prophetで任天堂ADR株価予測¶
m = fbprophet.Prophet()
m.fit(df1)
future = m.make_future_dataframe(periods=365)
future.tail()
forecast = m.predict(future)
forecast.tail()
fig = plot_plotly(m, forecast) # This returns a plotly Figure
layout = dict(title = '任天堂ADR株価予測',
title_font=dict(size=24, family='Courier', color='black'),
yaxis=dict(title='株価',title_font=dict(size=22)
,tickfont=dict(size=20)),
xaxis=dict(title='年',title_font=dict(size=22),tickfont=dict(size=20)),
autosize=False,width=800, height=640,
hovermode= 'x',
hoverlabel=dict(font=dict(size=24)),
legend=dict(x=-.001,y=1,font=dict(size=21,color='black'),bgcolor='rgba(0,0,0,0)'),
legend_orientation="v"
)
fig.layout.update(layout)
plot(fig,show_link=False,filename="stock_price_nintendo_adr.html",include_plotlyjs=False)
任天堂ADRの場合、来年は上昇局面に入り、2018年3月の高値を超える可能性があるみたいです。
スポンサーリンク
スポンサーリンク
コメント