Skip to main content


In this tutorial we will learn how to use the FORECAST function to predict Apple's stock prices using Infer's special flavour of SQL, SQL-inf!


What is Forecasting?

Forecasting is a way of predicting what will happen in the future (!) based on past data and trends. 🔮 It's used in many fields, such as business (predicting stock price), economics, and meteorology (weather forecasting), to make informed decisions and plans. Forecasting can be challenging because the future is uncertain and there are often many factors at play, but it can be a valuable tool for making informed predictions.


Time Series forecasting techniques learn a relationship (or function f), that maps time (and sometimes other inputs) to (approximately, ≈) predict the target (stock price).

At Infer, we use a very popular algorithm developed at Facebook called Prophet. You can read more about Prophet here. Essentially, Prophet breaks down any time series into four main components: a trend curve, a yearly seasonal component, a weekly seasonal component, and holidays. We can use these four components to help us understand what our time series is doing! More on this in a sec.

Using SQL-inf for Forecasting

Note that as we are currently in a beta launch, our Infer commands have been limited to using 10,000 randomly sampled rows instead of the entire dataset. This limitation will be lifted post-beta. This limitation does not apply to the DBT integration.

SQL-inf takes this state-of-the-art forecasting technique and turns it into a simple one-liner.

We upload a dataset for the Apple Stock Price from the S&P500 (i.e. stock market data!), with table name apple_stock. Next, we run our one-liner.

SELECT * FROM apple_stock FORECAST(high, time='date')

and we get a forecasting result! We've successfully forecasted the value of Apple stock for the next year!


We now several new columns. For now, most important columns are forecast and trend. forecast is the median predicted value, and the trend learned pattern of the forecast. Columns suffixed with _upper and _lower represent the 90th and 10th quantiles respectively. For the rest of the columns, see the reference documentation.

Auto-visualisation with Infer

The Infer platform will automatically begin to visualise the Forecast for you.


This is currently a bit limited for beta. We're working on better ways to interact with forecasting.