3 unstable releases
new 0.3.3 | May 19, 2025 |
---|---|
0.3.0 | May 19, 2025 |
0.2.0 | May 19, 2025 |
#12 in #statistics-analysis
29 downloads per month
Used in 5 crates
36KB
477 lines
OxiDiviner Core
The core components and traits for the OxiDiviner time series forecasting library.
Overview
This crate provides the fundamental building blocks for time series analysis and forecasting in the OxiDiviner ecosystem. It defines the common data structures, traits, and error handling mechanisms used by all OxiDiviner forecasting models.
Features
TimeSeriesData
- Flexible container for time series data with timestampsOHLCVData
- Specialized container for financial time series (Open-High-Low-Close-Volume)Forecaster
trait - Common interface for all forecasting models- Standardized model evaluation metrics
- Common error types and results
Usage
Add this to your Cargo.toml
:
[dependencies]
oxidiviner-core = "0.1.0"
Example
use oxidiviner_core::{TimeSeriesData, Forecaster, ModelOutput};
use chrono::{DateTime, Utc};
// Implementing a custom forecasting model
struct SimpleMovingAverage {
name: String,
window_size: usize,
values: Vec<f64>,
}
impl SimpleMovingAverage {
fn new(window_size: usize) -> Self {
Self {
name: format!("SMA({})", window_size),
window_size,
values: Vec::new(),
}
}
}
impl Forecaster for SimpleMovingAverage {
fn name(&self) -> &str {
&self.name
}
fn fit(&mut self, data: &TimeSeriesData) -> oxidiviner_core::Result<()> {
self.values = data.values().to_vec();
Ok(())
}
fn forecast(&self, horizon: usize) -> oxidiviner_core::Result<Vec<f64>> {
if self.values.is_empty() {
return Err(oxidiviner_core::OxiError::NotFitted);
}
// Use last window_size values to calculate the average
let start = self.values.len().saturating_sub(self.window_size);
let window = &self.values[start..];
let avg = window.iter().sum::<f64>() / window.len() as f64;
// Return the average for each forecasted point
Ok(vec![avg; horizon])
}
fn evaluate(&self, test_data: &TimeSeriesData) -> oxidiviner_core::Result<oxidiviner_core::ModelEvaluation> {
// Implementation omitted for brevity
unimplemented!()
}
}
License
Licensed under the MIT License. See LICENSE for details.
Dependencies
~8MB
~163K SLoC