FB data science team saw it forthcoming the age of data. They created their prophet to forecast data. While its use is not limited to stocks its a handy tool for anyone trying to understand number and movement. According to them, Prophet was made to:
make it easier for experts and non-experts to make high-quality forecasts that keep up with demand
Where Prophet shines
Not all forecasting problems can be solved by the same procedure. The prophet is optimized for the business forecast tasks we have encountered at Facebook, which typically have any of the following characteristics:
- hourly, daily, or weekly observations with at least a few months (preferably a year) of history
- strong multiple “human-scale” seasonalities: day of week and time of year
- important holidays that occur at irregular intervals that are known in advance (e.g. the Super Bowl)
- a reasonable number of missing observations or large outliers
- historical trend changes, for instance, due to product launches or logging changes
- trends that are non-linear growth curves, where a trend hits a natural limit or saturates
How Prophet works
At its core, the Prophet procedure is an additive regression model with four main components:
- A piecewise linear or logistic growth curve trend. Prophet automatically detects changes in trends by selecting changepoints from the data.
- A yearly seasonal component modelled using Fourier series.
- A weekly seasonal component using dummy variables.
- A user-provided list of important holidays.
y(t) = g(t) + s(t) + h(t) + ϵ
- g(t) models trend, which describes a long-term increase or decrease in the data. Prophet incorporates two trend models, a saturating growth model, and a piecewise linear model, depending on the type of forecasting problem.
- s(t) models seasonality with Fourier series, which describes how data is affected by seasonal factors such as the time of the year (e.g. more searches for eggnog during the winter holidays)
- h(t) models the effects of holidays or large events that impact business time-series ϵ. represents an irreducible error term
Using Prophet in Python
Setup
Start by importing all the necessary libraries. If you don’t already have Prophet installed, you can easily install it with pip.
pip install fbprophet
If you are getting the following error while using Jupiter
Use command
conda install -c conda-forge fbprophet
Import the packages
import nsepy as nse
from nsetools import Nse
import datetime
import urllib3
import random
import numpy as np
from fbprophet import Prophet
import pandas as pd
Full Code
import nsepy as nse
import datetimeimport jsonimport numpy as np
from fbprophet import Prophet
import pandas as pd
import requests
import import_ipynb
import pre as preprocessing
import matplotlib.pyplot as pltfrom fbprophet.plot import plot_cross_validation_metric
import math
endpoint = ‘https://min-api.cryptocompare.com/data/histoday’
res = requests.get(endpoint + ‘?fsym=USDT&tsym=CAD&limit=500’)hist = pd.DataFrame(json.loads(res.content)[‘Data’])
hist = hist.set_index(‘time’)
hist.index = pd.to_datetime(hist.index, unit=’s’)target_col = ‘close’hist.head(5)
hist[‘y’]=(hist[‘high’]+hist[‘low’])/2
hist[‘ds’]=hist.indexmodel = Prophet()
model.fit(hist);future = model.make_future_dataframe(periods=30)
#forecasting for 1 year from now.forecast = model.predict(future)figure=model.plot(forecast)
fig2 = model.plot_components(forecast)
Here the trend represents the overall trend of the stock. Weekly represents the cyclic nature in a weekly way and yearly tells us the cyclic nature in a year. Fig2 is used to break down the output into its core components.
That’s It!
Use this trick to predict and earn profits.
Found this article useful? Follow me (Rahula Raj) on Medium and check out my most popular articles below! Please this article to share it!
Leave a Reply