#!/usr/bin/env python # coding: utf-8 # In[9]: # Preliminaries import pandas as pd from exabel_data_sdk.client.api.export_api import ExportApi from exabel_data_sdk.query.column import Column export_api = ExportApi() # # Forecasting # Exabel offers multiple univariate forecast models directly available in the DSL, from the # [statsmodels](https://www.statsmodels.org) Python library and Facebook’s [Prophet](https://facebook.github.io/prophet/) library. # Forecasts are useful if you want to extend a time series into the future, e.g. for use in models. # ## Additive vs multiplicative models # All of these statistical methods are by default linear, meaning that they assume growth trends are linear with time and seasonality effects are additive. However, for typical financial KPIs such as revenue, it is more natural to assume that growth trends are exponential, meaning that a company’s revenue grows by a certain percentage each year rather than projecting that it will grow by a fixed amount per year. Similarly, it is more natural to assume that the seasonality trends are multiplicative, meaning that revenue in Q4 is modelled to be e.g. 20% higher than in Q3, rather than modelled to be $50M higher in Q4. # # Such time series can be modelled with exponential growth and multiplicative seasonality by taking the logarithm first, forecasting the logarithmic values, and finally exponentiating to get back the original values. # # Let's compare the difference in the produced forecasts with an example: # In[25]: company = "CMG US" sales_actual = export_api.signal_query("Sales_Actual_fiscal", company, start_time='2011-01-01') columns = [ Column("Additive", f"Sales_Actual_fiscal.forecast('theta', 'forecast', estimation_end='2016-12-31')"), Column("Multiplicative", f"Sales_Actual_fiscal.log().forecast('theta', 'forecast', estimation_end='2016-12-31').exp()"), ] forecasts = export_api.signal_query(columns, company) df = pd.concat([sales_actual, forecasts], axis=1) df.plot(figsize=(15, 5)); # ## Model types #