anofox-forecast
Technical depth grading and code quality analysis powered by pmat
Time series forecasting library for Rust.
Provides 35+ forecasting models, 76+ statistical features, seasonality decomposition, changepoint detection, anomaly detection, and bootstrap confidence intervals.
Features
-
Forecasting Models (35+)
- ARIMA and AutoARIMA with automatic order selection
- Exponential Smoothing: Simple (SES), Holt's Linear, Holt-Winters
- ETS (Error-Trend-Seasonal) state-space framework with AutoETS
- Baseline methods: Naive, Seasonal Naive, Random Walk with Drift, Simple Moving Average
- Theta method for forecasting
- Intermittent demand models: Croston, ADIDA, TSB
- Ensemble methods with multiple combination strategies
-
Time Series Feature Extraction (76+ features)
- Basic statistics (mean, variance, quantiles, energy, etc.)
- Distribution features (skewness, kurtosis, symmetry)
- Autocorrelation and partial autocorrelation
- Entropy features (approximate, sample, permutation, binned, Fourier)
- Complexity measures (C3, CID, Lempel-Ziv)
- Trend analysis and stationarity tests (ADF, KPSS)
-
Seasonality & Decomposition
- STL (Seasonal-Trend decomposition using LOESS)
- MSTL (Multiple Seasonal-Trend decomposition) for complex seasonality
-
Spectral Analysis
- Welch's periodogram for reduced variance spectral estimation
- For comprehensive periodicity detection, see fdars
-
Changepoint Detection
- PELT algorithm with O(n) average complexity
- Multiple cost functions: L1, L2, Normal, Poisson, LinearTrend, MeanVariance, Cusum
-
Anomaly Detection
- Statistical methods (IQR, z-score)
- Automatic threshold selection
- Seasonality-aware detection
-
Bootstrap Confidence Intervals
- Residual bootstrap and block bootstrap methods
- Empirical confidence intervals for any model
- Configurable sample size and reproducibility
-
Probabilistic Postprocessing
- Conformal Prediction: Distribution-free intervals with coverage guarantees
- Historical Simulation: Non-parametric empirical error distribution
- Normal Predictor: Gaussian error assumption baseline
- IDR: Isotonic Distributional Regression (state-of-the-art calibration)
- QRA: Quantile Regression Averaging for ensemble combining
- Backtesting: Rolling/expanding window evaluation with horizon-aware calibration
-
Data Transformations
- Scaling: standardization, min-max, robust scaling
- Box-Cox transformation with automatic lambda selection
- Window functions: rolling mean, std, min, max, median
- Exponential weighted moving averages
-
Model Evaluation & Validation
- Accuracy metrics: MAE, MSE, RMSE, MAPE, and more
- Time series cross-validation
- Residual testing and diagnostics
Installation
Add this to your Cargo.toml:
[]
= "0.3"
For parallel AutoARIMA (4-8x speedup):
[]
= { = "0.3", = ["parallel"] }
Quick Start
Creating a Time Series
use *;
use ;
// Create timestamps
let timestamps: =
.map
.collect;
// Create values
let values: = .map.collect;
// Build the time series
let ts = builder
.timestamps
.values
.build?;
ARIMA Forecasting
use *;
use Arima;
// Create and fit an ARIMA(1,1,1) model
let mut model = new?;
model.fit?;
// Generate forecasts with 95% confidence intervals
let forecast = model.predict_with_intervals?;
println!;
println!;
println!;
Holt-Winters Forecasting
use HoltWinters;
// Create Holt-Winters with additive seasonality (period = 12)
let mut model = additive?;
model.fit?;
let forecast = model.predict?;
Feature Extraction
use ;
let values = ts.values;
let m = mean;
let v = variance;
let s = skewness;
let ae = approximate_entropy?;
println!;
STL Decomposition
use Stl;
// Decompose with seasonal period of 12
let stl = new?;
let decomposition = stl.decompose?;
println!;
println!;
println!;
Changepoint Detection
use ;
let pelt = new?;
let changepoints = pelt.detect?;
println!;
Spectral Analysis
use welch_periodogram;
// Welch's periodogram with overlapping windows
let psd = welch_periodogram;
// Find dominant period
if let Some = psd.iter.max_by
For comprehensive periodicity detection (ACF, FFT, Autoperiod, CFD-Autoperiod, SAZED), see the fdars crate.
Probabilistic Postprocessing
use ;
// Historical forecasts and actuals for calibration
let train_forecasts = from_values;
let train_actuals = vec!;
// Create a conformal predictor with 90% coverage
let processor = conformal;
// Backtest with horizon-aware calibration
let config = new
.initial_window
.step
.horizon
.horizon_aware;
let results = processor.backtest?;
println!;
// Train calibrated model and predict
let trained = processor.train?;
let new_forecasts = from_values;
let intervals = processor.predict_intervals?;
println!;
println!;
API Reference
Core Types
| Type | Description |
|---|---|
TimeSeries |
Main data structure for univariate/multivariate time series |
Forecast |
Prediction results with optional confidence intervals |
CalendarAnnotations |
Holiday and regressor management |
AccuracyMetrics |
Model evaluation metrics (MAE, MSE, RMSE, MAPE, etc.) |
Forecasting Models
| Model | Description |
|---|---|
Arima |
ARIMA(p,d,q) model |
AutoArima |
Automatic ARIMA order selection |
Ses |
Simple Exponential Smoothing |
Holt |
Holt's Linear Trend method |
HoltWinters |
Holt-Winters with seasonal components |
Ets |
ETS state-space model |
AutoEts |
Automatic ETS model selection |
Naive |
Naive forecasting |
SeasonalNaive |
Seasonal naive forecasting |
Theta |
Theta method |
Croston |
Croston's method for intermittent demand |
Feature Categories
| Category | Examples |
|---|---|
| Basic | mean, variance, minimum, maximum, quantile |
| Distribution | skewness, kurtosis, variation_coefficient |
| Autocorrelation | autocorrelation, partial_autocorrelation |
| Entropy | approximate_entropy, sample_entropy, permutation_entropy |
| Complexity | c3, cid_ce, lempel_ziv_complexity |
| Trend | linear_trend, adf_test, ar_coefficient |
Postprocessing Types
| Type | Description |
|---|---|
PostProcessor |
Unified API for all postprocessing methods |
PointForecasts |
Wrapper for point forecast values |
QuantileForecasts |
Multi-quantile forecast container |
PredictionIntervals |
Lower/upper bound intervals |
BacktestConfig |
Configuration for rolling/expanding backtests |
BacktestResult |
Backtest metrics with per-horizon analysis |
ConformalPredictor |
Distribution-free prediction intervals |
HistoricalSimulator |
Empirical error distribution |
IDRPredictor |
Isotonic Distributional Regression |
QRAPredictor |
Quantile Regression Averaging |
Dependencies
- chrono - Date and time handling
- faer - Linear algebra operations
- statrs - Statistical distributions and functions
- thiserror - Error handling
- rand - Random number generation
- rustfft - Fast Fourier Transform for spectral analysis
Acknowledgments
The postprocessing module is a Rust port of PostForecasts.jl. Feature extraction is inspired by tsfresh. Forecasting models are validated against StatsForecast by Nixtla. See THIRDPARTY_NOTICE.md for full attribution and references to the research papers that inspired this implementation.
License
MIT License - see LICENSE for details.