Crates.io | oxidiviner-core |
lib.rs | oxidiviner-core |
version | 0.3.3 |
created_at | 2025-05-19 18:54:17.16449+00 |
updated_at | 2025-05-19 20:47:53.503042+00 |
description | Core functionality for OxiDiviner time series analysis library |
homepage | https://github.com/rustic-ml/OxiDiviner |
repository | https://github.com/rustic-ml/OxiDiviner |
max_upload_size | |
id | 1680256 |
size | 37,357 |
The core components and traits for the OxiDiviner time series forecasting library.
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.
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 modelsAdd this to your Cargo.toml
:
[dependencies]
oxidiviner-core = "0.1.0"
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!()
}
}
Licensed under the MIT License. See LICENSE for details.