[PYTHON] I used Facebook's Prophet to predict the Dow Jones Industrial Average.

Reference link: Document

What is Prophet?

Prophet is a tool developed by Facebook to predict time series data. It seems that it is fast and fully automatic. Let's use it for a moment.

Target data

Uses the daily Dow Jones Industrial Average since 1948.

Installation

pip install fbprophet
import fbprophet
fbprophet.__version__
#'0.6'

Data import

The format must be columns = ["ds", "y"].

ds y
18356 2020-04-23 23515.26
18357 2020-04-24 23775.27
18358 2020-04-27 24133.78
18359 2020-04-28 24101.55
18360 2020-04-29 24633.86
18361 2020-04-30 24345.72
18362 2020-05-01 23723.69
18363 2020-05-04 23749.76
18364 2020-05-05 23883.09
18365 2020-05-06 23664.64
18366 2020-05-07 23875.89
18367 2020-05-08 24331.32

Create an instance of Prophet object and fit it.

m = Prophet(daily_seasonality=True)
m.fit(df)

If the frequency of time series data is not daily but hourly, set daily_seasonality = True.

Create future data frames.

future = m.make_future_dataframe(periods=365)
future.tail()
ds
18728 2021-05-04
18729 2021-05-05
18730 2021-05-06
18731 2021-05-07
18732 2021-05-08

Predict.

forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
ds yhat yhat_lower yhat_upper
18728 2021-05-04 25240.993067 23775.034765 26676.954454
18729 2021-05-05 25241.812462 23873.631394 26743.879477
18730 2021-05-06 25248.372948 23662.176440 26658.218006
18731 2021-05-07 25251.123010 23590.352159 26721.447848
18732 2021-05-08 25258.034603 23780.066094 26742.194673

Here, I will explain the variables -** yhat : Predicted value - yhat_lower : Lower limit of predicted error - yhat_upper **: Upper limit of predicted error

Plot.

fig1 = m.plot(forecast)

plot_with_prophet.png

It is generally within the margin of error.

View individual elements.

fig2 = m.plot_components(forecast)

plot_components.png

Sure, the quote says "Sell in May and go away, and come on back on St. Leger's Day." (Sell stocks in May and don't come back until St. Leger's Day (mid-September)) There is a saying. This seems to be something (laughs)

This is the basic usage, please see the document for more details.

Recommended Posts

I used Facebook's Prophet to predict the Dow Jones Industrial Average.
I tried to predict the price of ETF
I tried to predict the J-League match (data analysis)
I tried to find the average of the sequence with TensorFlow
I tried to summarize the code often used in Pandas
I tried to summarize the commands often used in business
[Note] Let's try to predict the amount of electricity used! (Part 1)
I tried to summarize the commands used by beginner engineers today
I tried to predict by letting RNN learn the sine wave
I tried to summarize the frequently used implementation method of pytest-mock
I used the worldcup command to check the outcome of the World Cup.
Can the Kalman filter be used to predict stock price trends?
I calculated the stochastic integral (I to integral)
I tried to move the ball
I tried to estimate the interval.
I want to use the Qore SDK to predict the success of NBA players
I tried to summarize the Linux commands used by beginner engineers today-Part 1-
I tried the common story of using Deep Learning to predict the Nikkei 225
I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried to train the RWA (Recurrent Weighted Average) model in Keras