#time-series-analysis #statistics-analysis #statistics #forecasting #data-analysis #time-series

oxidiviner-moving-average

Moving average models for OxiDiviner time series analysis library

3 unstable releases

new 0.3.3 May 19, 2025
0.3.0 May 19, 2025
0.2.0 May 19, 2025

#2314 in Math

23 downloads per month
Used in oxidiviner

MIT license

50KB
652 lines

OxiDiviner Moving Average

Crates.io Documentation License: MIT

Moving average models for time series forecasting in the OxiDiviner ecosystem.

Overview

This crate provides implementations of Moving Average (MA) models for time series analysis and forecasting. MA models are useful for capturing short-term dependencies in time series data and are widely used in finance, economics, and signal processing.

Features

  • Implementation of MA(q) models
  • Parameter estimation using method of moments
  • Forecasting with confidence intervals
  • Model selection based on information criteria
  • Integration with the OxiDiviner forecasting ecosystem

Model Definition

The Moving Average model MA(q) is defined as:

Y_t = μ + ε_t + θ_1*ε_{t-1} + θ_2*ε_{t-2} + ... + θ_q*ε_{t-q}

Where:

  • Y_t is the time series value at time t
  • μ is the mean of the process
  • ε_t is white noise at time t
  • θ_i are the model parameters
  • q is the order of the moving average process

Usage

Add this to your Cargo.toml:

[dependencies]
oxidiviner-moving-average = "0.1.0"
oxidiviner-core = "0.1.0"

Example

use oxidiviner_core::{TimeSeriesData, Forecaster};
use oxidiviner_moving_average::MAModel;
use chrono::{Utc, TimeZone};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create sample time series data
    let dates = (0..10).map(|i| Utc.timestamp_opt(1609459200 + i * 86400, 0).unwrap()).collect();
    let values = vec![1.0, 1.2, 1.1, 1.3, 1.4, 1.3, 1.5, 1.4, 1.6, 1.5];
    let data = TimeSeriesData::new(dates, values)?;
    
    // Create an MA(2) model
    let mut model = MAModel::new(2)?;
    
    // Fit the model to the data
    model.fit(&data)?;
    
    // Display the fitted model
    println!("Model: {}", model);
    
    // Generate forecasts for the next 5 time steps
    let forecasts = model.forecast(5)?;
    println!("Forecasts: {:?}", forecasts);
    
    // Get a complete model output including evaluation metrics
    let output = model.predict(5, None)?;
    
    Ok(())
}

License

Licensed under the MIT License. See LICENSE for details.

Dependencies

~7.5MB
~153K SLoC