Time Series Forecasting for DuckDB
Technical Depth: A (93%) | Code Health: A- (90%) - calculated using PMAT
A time series forecasting extension for DuckDB with 36 models, statistical diagnostics, data preparation, and analytics β all in pure SQL.
π€ Built for AI pair-programming. anofox-forecast ships an installable Claude Code plugin β five skills that give your AI assistant verified, hallucination-free knowledge of the full SQL API. Describe the forecast in plain English; Claude writes correct
ts_forecast_by, ensemble, backtest, and diagnostics queries.Install with
/plugin marketplace add DataZooDE/anofox-forecastβ/plugin install anofox-forecast@anofox-forecast.
- AutoML: AutoETS, AutoARIMA, AutoTBATS, plus the deprecated-but-accepted aliases AutoMFLES/AutoMSTL (same code path as MFLES/MSTL, reported
model_namematches the bare family name) - Statistical: ETS, ARIMA, Theta, Holt-Winters, Seasonal Naive
- Advanced: TBATS, MSTL, MFLES (multiple seasonality)
- Intermittent Demand: Croston, ADIDA, IMAPA, TSB
- Distributional: Laplace (streaming likelihood-weighted mixture, three zero-config selectors:
auto/auto_aid/skaters) - Volatility & State-Space: GARCH (conditional volatility), Kalman filter (local-level / local-linear-trend)
- Global / Panel: GlobalETS, GlobalTheta, GlobalCroston β cross-series "fit once, forecast all" via
ts_forecast_panel_by - Multivariate: VAR (vector autoregression) via
ts_forecast_var_byβ N value columns β per-variable forecasts - Exogenous Variables: crate-native exog support for Naive, ARIMA, AutoARIMA, the Theta family, ETS/AutoETS, MFLES, and MSTL β reported
model_nameis the base model's own name with" with regressors"appended (no separate model name)
- Stationarity: ADF, KPSS, and a combined four-way verdict, each with
regression := 'c'(default) or'ct'for trend-stationarity (ts_adf_by,ts_kpss_by,ts_stationarity_by) - Residual Adequacy: Ljung-Box (model-aware via
fitted_params := p + q, RBox.test(fitdf)-exact), Durbin-Watson, Jarque-Bera, plus a combined pass/fail report (ts_residual_diagnostics_by) - Reference-checked: Ljung-Box, Jarque-Bera, Durbin-Watson, and the KPSS statistic are numerically cross-checked against R (
stats::Box.test,tseries) and scipy; ADF/KPSS p-values are a coarse approximation, not cross-validated (seedocs/api/10-diagnostics.md)
- EDA & Data Quality: 5 functions (2 table functions, 3 macros) for exploratory analysis and data quality assessment
- Data Preparation: 12 macros for cleaning and transformation
- Multi-Key Hierarchy: 4 functions for combining, aggregating, and splitting hierarchical time series (region/store/item)
- Cross-Validation & Backtesting: Time series CV with expanding/fixed/sliding windows, gap, embargo, and variable horizon support
- Conformal Prediction: Distribution-free prediction intervals, horizon-ordered and calibrated per group, plus residual-resampling bootstrap intervals (see
docs/api/11-conformal-prediction.md) - Evaluation: 12 metrics including coverage analysis
- Seasonality Detection: Automatic period identification, seasonality classification, and peak detection
- Changepoint Detection: Regime identification with probabilities
- 117 Statistical Features: Extract comprehensive time series features for ML pipelines
- GROUP BY & Window Support: Native DuckDB parallelization for multi-series feature extraction
- Flexible Configuration: Select specific features, customize parameters, or use JSON/CSV configs
- tsfresh-Inspired: Feature vectors inspired by tsfresh's naming/catalogue; a documented subset of features deviates from tsfresh's exact formulas (see
docs/api/21-feature-reference.md)
- Parallel: Native DuckDB parallelization on GROUP BY
- Scalable: Handles millions of series
- Memory Efficient: Columnar storage, streaming operations
- Native Rust Core: High-performance native implementations for data preparation and forecasting
- Zero Setup: All macros load automatically
- Consistent: MAP-based parameters
- Composable: Chain operations easily
- Multi-Language: Use from Python, R, Julia, C++, Rust, and more!
- Key Features
- Claude Code Skills (AI pair-programming)
- Installation
- Quick Start on M5 Dataset
- Multi-Language Support
- API Reference
- Development
- License
Forecasting is easier when your AI assistant actually knows the API. anofox-forecast ships an installable Claude Code plugin β five skills that give Claude deep, source-verified knowledge of every function, MAP/STRUCT option, and return column. Instead of guessing at signatures, Claude writes correct SQL from a plain-English request like "forecast each store with an AutoETS/Theta ensemble and attach 90% conformal intervals" or "backtest AutoARIMA per SKU and give me MASE."
Install in any Claude Code session:
/plugin marketplace add DataZooDE/anofox-forecast
/plugin install anofox-forecast@anofox-forecast
| Skill | Covers |
|---|---|
anofox-forecast-models |
36 models + ensembles; ts_forecast_by / ts_forecast_ensemble_by / ts_forecast_var_by |
anofox-forecast-backtest |
Cross-validation, metrics, conformal prediction intervals |
anofox-forecast-eda |
Per-series stats, data quality, 117 features, stationarity/residual diagnostics |
anofox-forecast-detection |
Seasonality, period, changepoint, peak detection |
anofox-forecast-data-prep |
Gap filling, imputation, differencing, hierarchical keys |
The skills live in plugins/anofox-forecast/. make check-docs (and a CI job that gates every deploy) runs each of their SQL examples against the shipped extension, resolves every function name they mention, and checks that they carry the released version. For in-repo development, load them directly with claude --plugin-dir ./plugins/anofox-forecast.
This extension uses the anofox-forecast Rust crate and implements algorithms from several open-source projects.
See THIRD_PARTY_NOTICES.md for complete attribution and license information.
INSTALL anofox_forecast FROM community;
LOAD anofox_forecast;To upgrade an already-installed copy, use
FORCE INSTALL anofox_forecast FROM community;β a plainINSTALLis a no-op when a build is already cached locally.
For the freshest builds β ahead of the community-extensions cadence β install from DataZoo's own extension repository. These binaries are unsigned (independent of the DuckDB Foundation), so start DuckDB with the -unsigned flag. This command requires outbound network access and will error in a network-restricted environment:
-- launch with: duckdb -unsigned
INSTALL anofox_forecast FROM 'http://get.erpl.io';
LOAD anofox_forecast;(Use FORCE INSTALL β¦ FROM 'http://get.erpl.io'; to refresh an already-cached copy.) Builds are published there for DuckDB v2.0.0 and v1.5.6.
# Clone the repository
git clone --recurse-submodules https://github.com/DataZooDE/anofox-forecast.git
cd anofox-forecast
# Build the extension (choose one)
# This step requires Rust >= 1.89 (workspace rust-version) and CMake
make release -j$(nproc) # With Make OR
GEN=ninja make release # With Ninja (faster)
# The extension will be built to:
# build/release/extension/anofox_forecast/anofox_forecast.duckdb_extensionThe duckdb submodule is pinned to v2.0.0, so a source build targets DuckDB v2.0.0. To build for v1.5.6, check out the duckdb submodule at that tag and extension-ci-tools at v1.5-variegata / v1.4-andium.
π€ Using an AI assistant? Install the Claude Code skills plugin so it knows the full SQL API.
The forecast takes ~2 minutes on a Dell XPS 13. (Requires DuckDB v2.0.0 or v1.5.6). This
loads httpfs and reads a remote parquet file, so it requires outbound network access and the
httpfs extension binary and will error without either:
-- Load extension
LOAD httpfs;
LOAD anofox_forecast;
CREATE OR REPLACE TABLE m5 AS
SELECT item_id, CAST(timestamp AS TIMESTAMP) AS ds, demand AS y FROM 'https://m5-benchmarks.s3.amazonaws.com/data/train/target.parquet'
ORDER BY item_id, timestamp;
CREATE OR REPLACE TABLE m5_train AS
SELECT * FROM m5 WHERE ds < DATE '2016-04-25';
CREATE OR REPLACE TABLE m5_test AS
SELECT * FROM m5 WHERE ds >= DATE '2016-04-25';
-- Forecast with multiple models
CREATE OR REPLACE TABLE forecast_results AS (
SELECT * FROM ts_forecast_by('m5_train', item_id, ds, y, 'SeasonalNaive', 28, '1d', MAP{'seasonal_period': '7'})
UNION ALL
SELECT * FROM ts_forecast_by('m5_train', item_id, ds, y, 'Theta', 28, '1d', MAP{'seasonal_period': '7'})
UNION ALL
SELECT * FROM ts_forecast_by('m5_train', item_id, ds, y, 'AutoARIMA', 28, '1d', MAP{'seasonal_period': '7'})
);
-- Join forecasts with actuals and create composite key for grouping
CREATE OR REPLACE TABLE forecast_vs_actual AS
SELECT
f.item_id,
f.model_name,
f.item_id || '|' || f.model_name AS series_key,
f.ds,
t.y AS actual,
f.yhat AS forecast
FROM forecast_results f
JOIN m5_test t ON f.item_id = t.item_id AND f.ds = t.ds;
-- MAE and Bias per series using scalar metrics + GROUP BY
-- (recommended over the deprecated ts_*_by table macros β ~2400x faster, parallel-safe)
CREATE OR REPLACE TABLE evaluation_results AS
SELECT
item_id,
model_name,
ts_mae(LIST(actual ORDER BY ds), LIST(forecast ORDER BY ds)) AS mae,
ts_bias(LIST(actual ORDER BY ds), LIST(forecast ORDER BY ds)) AS bias
FROM forecast_vs_actual
GROUP BY item_id, model_name;
-- Summarise evaluation results by model
SELECT
model_name,
AVG(mae) AS avg_mae,
STDDEV(mae) AS std_mae,
AVG(bias) AS avg_bias,
STDDEV(bias) AS std_bias
FROM evaluation_results
GROUP BY model_name
ORDER BY avg_mae;Write SQL once, use everywhere! The extension works from any language with DuckDB bindings.
| Language | Status | Notes |
|---|---|---|
| Python | β | Via DuckDB Python bindings |
| R | β | Via DuckDB R bindings |
| Julia | β | Via DuckDB Julia bindings |
| C++ | β | Via DuckDB C++ bindings |
| Rust | β | Via DuckDB Rust bindings |
| Node.js | β | Via DuckDB Node bindings |
| Go | β | Via DuckDB Go bindings |
| Java | β | Via DuckDB JDBC driver |
For complete function signatures, parameters, and detailed documentation, see the API Reference.
| Category | Description | Documentation |
|---|---|---|
| Getting Started | Installation and first forecast | Getting Started Guide |
| Model Selection | Choose the right model | Model Selection Guide |
| Cross-Validation | Evaluate forecast accuracy | Cross-Validation Guide |
| Monitoring | Alerts and forecast refreshes on INSERT (DuckDB 2.0) | Monitoring with Triggers |
| Topic | Description | Reference |
|---|---|---|
| Hierarchical Data | Multi-key hierarchy functions | 02-hierarchical.md |
| Statistics | 34 statistical metrics, data quality | 03-statistics.md |
| Data Preparation | Cleaning, imputation, filtering | 04-data-preparation.md |
| Period Detection | Seasonality detection (12 methods) | 05-period-detection.md |
| Changepoint Detection | Structural break detection | 06-changepoint-detection.md |
| Forecasting | 36 forecasting models (incl. GARCH, Kalman, Global/panel, VAR) | 07-forecasting.md |
| Statistical Diagnostics | Stationarity (ADF/KPSS) & residual adequacy tests | 10-diagnostics.md |
| Cross-Validation | Backtesting and CV functions | 08-cross-validation.md |
| Evaluation Metrics | 12 accuracy metrics | 09-evaluation-metrics.md |
| Conformal Prediction | Distribution-free prediction intervals | 11-conformal-prediction.md |
| Feature Extraction | 117 tsfresh-inspired features | 20-feature-extraction.md |
| Category | Models | Reference |
|---|---|---|
| Baseline | Naive, SMA, SeasonalNaive, RandomWalkDrift | baseline/ |
| Exponential Smoothing | SES, Holt, HoltWinters, SeasonalES | exponential-smoothing/ |
| State Space | ETS, ARIMA, AutoETS, AutoARIMA, Kalman | state-space/ |
| Classical | GARCH (conditional volatility) | classical/garch.md |
| Theta | Theta, OptimizedTheta, DynamicTheta, AutoTheta | theta/ |
| Multi-Seasonal | MFLES, MSTL, TBATS (+ Auto variants) | multi-seasonal/ |
| Intermittent Demand | Croston, CrostonSBA, ADIDA, IMAPA, TSB | intermittent/ |
| Distributional | Laplace (variants: auto, auto_aid, skaters) | distributional/laplace.md |
| Global / Panel | GlobalETS, GlobalTheta, GlobalCroston (via ts_forecast_panel_by) |
global_ets.md |
| Multivariate | VAR (via ts_forecast_var_by) |
multivariate/var.md |
Before building, install the required dependencies:
Manjaro/Arch Linux:
sudo pacman -S base-devel cmake ninja openssl eigenUbuntu/Debian:
sudo apt update
sudo apt install build-essential cmake ninja-build libssl-dev libeigen3-devFedora/RHEL:
sudo dnf install gcc-c++ cmake ninja-build openssl-devel eigen3-develmacOS:
brew install cmake ninja openssl eigenWindows (Option 1 - vcpkg, recommended):
# Install vcpkg
git clone https://github.com/Microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
# Install dependencies
.\vcpkg\vcpkg install eigen3 openssl
# Build with vcpkg toolchain
cmake -DCMAKE_TOOLCHAIN_FILE=.\vcpkg\scripts\buildsystems\vcpkg.cmake .
cmake --build . --config ReleaseWindows (Option 2 - MSYS2/MinGW):
# In MSYS2 MinGW64 terminal
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
pacman -S mingw-w64-x86_64-openssl mingw-w64-x86_64-eigen3
# Then build as normal
make -j$(nproc)Windows (Option 3 - WSL, easiest):
# Use Ubuntu in WSL
wsl --install
# Then follow Ubuntu instructions aboveRequired:
- C++ compiler (GCC 9+ or Clang 10+)
- CMake 3.15+
- OpenSSL (development libraries)
- Eigen3 (linear algebra library)
- Make or Ninja (build system)
# Clone with submodules
git clone --recurse-submodules https://github.com/DataZooDE/anofox-forecast.git
cd anofox-forecast
# Set up Git hooks (recommended)
./scripts/setup-hooks.sh
# Build (choose one)
make -j$(nproc) # With Make
GEN=ninja make release # With Ninja (faster)This project uses Git hooks to ensure code quality before commits:
- cargo fmt - Enforces consistent code formatting
- cargo clippy - Catches common mistakes and enforces best practices
Setup the hooks after cloning:
./scripts/setup-hooks.shTo run checks manually:
cargo fmt --all # Format code
cargo clippy --workspace # Run linter
cargo test --workspace # Run tests# Test the extension
./build/release/duckdb -c "
LOAD 'build/release/extension/anofox_forecast/anofox_forecast.duckdb_extension';
SELECT 'Extension loaded successfully! β
' AS status;
"-- In DuckDB
LOAD 'path/to/anofox_forecast.duckdb_extension';
-- Verify all functions are available
SELECT * FROM ts_forecast_by('sales', product_id, date, amount, 'AutoETS', 7, '1d', MAP{'seasonal_period': '7'});Business Source License 1.1 (BSL 1.1)
β
Free for production use - Use internally in your business
β
Free for development - Build applications with it
β
Free for research - Academic and research use
β Cannot offer as hosted service - No SaaS offerings to third parties
β Cannot embed in commercial product - For third-party distribution
π Converts to MPL 2.0 - After 5 years from first publication
See LICENSE for full terms.
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Documentation: docs/
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: sm@data-zoo.de
If you use this extension in research, please cite:
@software{anofox_forecast,
title = {Anofox Forecast: Time Series Forecasting for DuckDB},
author = {Joachim Rosskopf, Simon MΓΌller, DataZoo GmbH},
year = {2025},
url = {https://github.com/DataZooDE/anofox-forecast}
}Built on top of:
- DuckDB - Amazing analytical database
- anofox-forecast - Core forecasting library
- anofox-regression - Regression and feature extraction
Special thanks to the DuckDB team for making extensions possible!
Made with β€οΈ by the Anofox Team
β Star us on GitHub if you find this useful!
π’ Follow us for updates: @datazoo
π Get started now: LOAD 'anofox_forecast';
If a forecast looks wrong or anofox_forecast misbehaves, please
open an issue. Forecast quality
depends on real seasonality, gaps and outliers we cannot reproduce from synthetic
series, so a report with your data shape is the fastest path to a fix.
If it saved you time, a star on the repo helps other people find it.
The first time you load the extension in an interactive terminal each day, a small
banner says the same thing. It never prints when output is piped, in notebooks, or in
CI. Silence it with SET datazoo_banner = false; or DATAZOO_NO_BANNER=1.