Prophet is a procedure for forecasting time series data. It is based on an additive model where non-linear trends are fit with yearly and weekly seasonality, plus holidays. It works best with daily periodicity data with at least one year of historical data. Prophet is robust to missing data, shifts in the trend, and large outliers.
Inspired by awesome David Sheehan blog post
In [1]:
import pandas as pd
import numpy as np
from fbprophet import Prophet
import time
import seaborn as sns
import matplotlib.pyplot as plt
import datetime
%matplotlib inline
In [46]:
import bs4
bs4.__version__
'4.4.1'
Out[46]:
In [48]:
import html5lib
html5lib.__version__
'0.9999999'
Out[48]:
In [51]:
# top 15 coins - at the time of writing this!
coins = ['bitcoin', 'ethereum', 'bitcoin-cash', 'ripple', 'litecoin', 'cardano', 'iota', 'dash', 'nem', 'monero', 'bitcoin-gold', 'stellar', 'neo', 'eos', 'ethereum-classic']
In [79]:
coin_market_info = {}
for coin in coins:
# getting data from 2017 until now!
coin_market_info[str(coin)] = pd.read_html("https://coinmarketcap.com/currencies/{0}/historical-data/?start=20170101&end={1}".format(str(coin),time.strftime("%Y%m%d")))[0]
coin_market_info[str(coin)] = coin_market_info[str(coin)].assign(Date=pd.to_datetime(bitcoin_market_info['Date']))
In [ ]:
In [97]:
prophets = {}
for coin in coins:
df = coin_market_info[str(coin)][['Date', 'Open']]
df = df.rename(index=str, columns={"Date": "ds", "Open": "y"})
# log-transform the prices
# df['y'] = np.log(df['y'])
prophets[str(coin)] = Prophet()
prophets[str(coin)].fit(df);
In [133]:
%%time
prophecies = {}
for coin in coins:
# predict price for next 90 days
prophecies[str(coin)] = prophets[str(coin)].make_future_dataframe(periods=120)
prophecies[str(coin)] = prophets[str(coin)].predict(future)
In [134]:
%%time
p = prophets['bitcoin'].plot(prophecies['bitcoin'])
pc = prophets['bitcoin'].plot_components(prophecies['bitcoin'])
In [135]:
%%time
coin = coins[1]
p = prophets[str(coin)].plot(prophecies[str(coin)])
pc = prophets[str(coin)].plot_components(prophecies[str(coin)])
In [136]:
%%time
coin = coins[2]
p = prophets[str(coin)].plot(prophecies[str(coin)])
pc = prophets[str(coin)].plot_components(prophecies[str(coin)])
In [137]:
%%time
coin = coins[3]
p = prophets[str(coin)].plot(prophecies[str(coin)])
pc = prophets[str(coin)].plot_components(prophecies[str(coin)])
In [138]:
%%time
coin = coins[4]
p = prophets[str(coin)].plot(prophecies[str(coin)])
pc = prophets[str(coin)].plot_components(prophecies[str(coin)])
In [139]:
%%time
coin = coins[5]
p = prophets[str(coin)].plot(prophecies[str(coin)])
pc = prophets[str(coin)].plot_components(prophecies[str(coin)])