Crates.io | oxidiviner-moving-average |
lib.rs | oxidiviner-moving-average |
version | 0.3.3 |
created_at | 2025-05-19 18:55:02.73581+00 |
updated_at | 2025-05-19 20:52:18.629989+00 |
description | Moving average models for OxiDiviner time series analysis library |
homepage | https://github.com/rustic-ml/OxiDiviner |
repository | https://github.com/rustic-ml/OxiDiviner |
max_upload_size | |
id | 1680257 |
size | 31,515 |
Moving average models for time series forecasting in the OxiDiviner ecosystem.
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.
The Moving Average model MA(q) is defined as:
Y_t = μ + ε_t + θ_1*ε_{t-1} + θ_2*ε_{t-2} + ... + θ_q*ε_{t-q}
Where:
Add this to your Cargo.toml
:
[dependencies]
oxidiviner-moving-average = "0.1.0"
oxidiviner-core = "0.1.0"
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(())
}
Licensed under the MIT License. See LICENSE for details.