Forecasting by FB Prophet in Colab

There are many forecasting tools available in the market, even Excel worksheet also provides a simple forecasting function, which I have shown how to use it (Yiu, 2019). Other more sophisticated software can provide ARIMA and HP Filter methods for forecasting, but they can be costly.

I learned that FB Prophet provides an open source code and free forecasting tool in R or Python. It allows more detailed parameter settings for making forecasts including three additive components: trend, seasonality and holidays. For more details, one may refer Lyla (2019).

Here is a trial of building a forecaster of HSI. To make it very simple, I simply do the following two tasks:

  1. read and plot time series data from Yahoo Finance into Colab; and
  2. make a forecast on the time series by FB Prophet.

If you do not know how to use Colab, please refer to my previous article at Yiu (2020). For more information of FB Prophet, here is the link — This simple example has only 10 routines, see whether they are correct or not. All lines start with a # sign are remarks only:

1. install FB Prophet and yfinance

2. import pd, plt and Prophet

3. read the time series data (here I use ^HSI from Yahoo Finance)

You may also read data directly from an URL, for example, the data provided in the Our World in Data website are downloadable via an URL. For example, you can program in Colab by: url=”"


4. show the data collected

5. plot the time series chart

6. define data x, y

7. define the parameters for the forecasting model — trend and seasonality

8. define the forecasting model

9. define the forecast

10. plot the chart with the forecast

Here shows the results. Figure 1 shows the HSI and its forecast by FB Prophet. Figure 2 shows the forecast components, with the upper chart shows the trend and the lower chart shows the seasonality.

Figure 1 Time Series and Forecast by FB Prophet
Figure 2 Forecast Components by FB Prophet

If you would like to show the forecasting values in numeric figures, you can program in Colab by:

The first two rows extend the default maximum numbers of rows and columns from 5 to no-limit, thus all the data will be shown. The third row specifies the table in four columns, showing the date, forecasting value, lower bound and upper bound, respectively, as illustrated below.

— —

I have uploaded my1st Time Series Forecaster by FBProphet at the following Github:

I also produce a Youtube at (Yiu, 2021) to explain in details.

[Caveat: this is just a trial and the forecast is not sophisticated enough to discuss for real life predictions. Please do not consider the results as any advice on the future predictions.]


Jain, A. P. (2021) ARIMA & SARIMA: Real-World Time Series Forecasting (Advanced Guide), neptune blog, 31 May.

Lyla, Y. (2019) A Quick Start of Time Series Forecasting with a Practical Example using FB Prophet, Medium, Jan 3.

Yiu, C.Y. (2019) Excel Forecasts a 40% Plummet of HK Housing Price! Medium, Apr 15.

Yiu, C.Y. (2020) Learning Machine Learning — How to Code without Learning Coding, Medium, Feb 6.

Yiu, C.Y. (2021) My First Forecaster by FB Prophet in Colab, Youtube, May 31.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

ecyY — easy to understand why, easy to study why. Finding the truths scientifically is the theme.