| Crates.io | anofox-forecast |
| lib.rs | anofox-forecast |
| version | 0.4.1 |
| created_at | 2025-12-12 15:30:30.023571+00 |
| updated_at | 2026-01-16 09:10:37.18237+00 |
| description | Time series forecasting library - Rust port of anofox-time |
| homepage | |
| repository | https://github.com/sipemu/anofox-forecast |
| max_upload_size | |
| id | 1981721 |
| size | 6,147,706 |
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.
Need to run this on 10GB of data? Use our DuckDB extension for SQL-native forecasting at scale.
Need to use this in a React Dashboard? Use our npm package for WebAssembly-powered forecasting in the browser.
npm install @sipemu/anofox-forecast
import init, { TimeSeries, NaiveForecaster, AutoETSForecaster } from '@sipemu/anofox-forecast';
await init();
const ts = new TimeSeries([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
const model = new AutoETSForecaster();
model.fit(ts);
const forecast = model.predict(5);
console.log(forecast.values); // [11, 12, 13, 14, 15] (approx)
Forecasting Models (35+)
Time Series Feature Extraction (76+ features)
Seasonality & Decomposition
Spectral Analysis
Changepoint Detection
Anomaly Detection
Bootstrap Confidence Intervals
Probabilistic Postprocessing
Data Transformations
Model Evaluation & Validation
Add this to your Cargo.toml:
[dependencies]
anofox-forecast = "0.4"
For parallel AutoARIMA (4-8x speedup):
[dependencies]
anofox-forecast = { version = "0.3", features = ["parallel"] }
use anofox_forecast::prelude::*;
use chrono::{TimeZone, Utc};
// Create timestamps
let timestamps: Vec<_> = (0..100)
.map(|i| Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap() + chrono::Duration::days(i))
.collect();
// Create values
let values: Vec<f64> = (0..100).map(|i| (i as f64 * 0.1).sin() + 10.0).collect();
// Build the time series
let ts = TimeSeries::builder()
.timestamps(timestamps)
.values(values)
.build()?;
use anofox_forecast::prelude::*;
use anofox_forecast::models::arima::Arima;
// Create and fit an ARIMA(1,1,1) model
let mut model = Arima::new(1, 1, 1)?;
model.fit(&ts)?;
// Generate forecasts with 95% confidence intervals
let forecast = model.predict_with_intervals(12, 0.95)?;
println!("Point forecasts: {:?}", forecast.values());
println!("Lower bounds: {:?}", forecast.lower());
println!("Upper bounds: {:?}", forecast.upper());
use anofox_forecast::models::exponential::HoltWinters;
// Create Holt-Winters with additive seasonality (period = 12)
let mut model = HoltWinters::additive(12)?;
model.fit(&ts)?;
let forecast = model.predict(24)?;
use anofox_forecast::features::{mean, variance, skewness, approximate_entropy};
let values = ts.values();
let m = mean(values);
let v = variance(values);
let s = skewness(values);
let ae = approximate_entropy(values, 2, 0.2)?;
println!("Mean: {}, Variance: {}, Skewness: {}, ApEn: {}", m, v, s, ae);
use anofox_forecast::seasonality::Stl;
// Decompose with seasonal period of 12
let stl = Stl::new(12)?;
let decomposition = stl.decompose(&ts)?;
println!("Trend: {:?}", decomposition.trend());
println!("Seasonal: {:?}", decomposition.seasonal());
println!("Remainder: {:?}", decomposition.remainder());
use anofox_forecast::changepoint::{Pelt, CostFunction};
let pelt = Pelt::new(CostFunction::L2, 10.0)?;
let changepoints = pelt.detect(&ts)?;
println!("Changepoints at indices: {:?}", changepoints);
use anofox_forecast::detection::welch_periodogram;
// Welch's periodogram with overlapping windows
let psd = welch_periodogram(&values, 64, 0.5);
// Find dominant period
if let Some((period, power)) = psd.iter().max_by(|a, b| a.1.partial_cmp(&b.1).unwrap()) {
println!("Dominant period: {}, power: {:.4}", period, power);
}
For comprehensive periodicity detection (ACF, FFT, Autoperiod, CFD-Autoperiod, SAZED), see the fdars crate.
use anofox_forecast::postprocess::{PostProcessor, PointForecasts, BacktestConfig};
// Historical forecasts and actuals for calibration
let train_forecasts = PointForecasts::from_values(train_f);
let train_actuals = vec![/* ... */];
// Create a conformal predictor with 90% coverage
let processor = PostProcessor::conformal(0.90);
// Backtest with horizon-aware calibration
let config = BacktestConfig::new()
.initial_window(100)
.step(10)
.horizon(7)
.horizon_aware(true);
let results = processor.backtest(&train_forecasts, &train_actuals, config)?;
println!("Coverage: {:.1}%", results.coverage() * 100.0);
// Train calibrated model and predict
let trained = processor.train(&train_forecasts, &train_actuals)?;
let new_forecasts = PointForecasts::from_values(new_f);
let intervals = processor.predict_intervals(&trained, &new_forecasts)?;
println!("Lower: {:?}", intervals.lower());
println!("Upper: {:?}", intervals.upper());
| 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.) |
| 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 |
| 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 |
| 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 |
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.
MIT License - see LICENSE for details.