40 lines
No EOL
1.2 KiB
Rust
40 lines
No EOL
1.2 KiB
Rust
// Technical Analysis Indicators Library
|
|
pub mod sma;
|
|
pub mod ema;
|
|
pub mod rsi;
|
|
pub mod macd;
|
|
pub mod bollinger_bands;
|
|
pub mod stochastic;
|
|
pub mod atr;
|
|
pub mod common;
|
|
|
|
// Re-export commonly used types and traits
|
|
pub use common::{IndicatorResult, IndicatorError, PriceData};
|
|
pub use sma::SMA;
|
|
pub use ema::EMA;
|
|
pub use rsi::RSI;
|
|
pub use macd::MACD;
|
|
pub use bollinger_bands::BollingerBands;
|
|
pub use stochastic::Stochastic;
|
|
pub use atr::ATR;
|
|
|
|
/// Trait that all indicators must implement
|
|
pub trait Indicator {
|
|
/// Calculate the indicator value(s) for the given data
|
|
fn calculate(&mut self, data: &PriceData) -> Result<IndicatorResult, IndicatorError>;
|
|
|
|
/// Reset the indicator state
|
|
fn reset(&mut self);
|
|
|
|
/// Check if the indicator has enough data to produce valid results
|
|
fn is_ready(&self) -> bool;
|
|
}
|
|
|
|
/// Trait for indicators that can be calculated incrementally
|
|
pub trait IncrementalIndicator: Indicator {
|
|
/// Update the indicator with a new data point
|
|
fn update(&mut self, value: f64) -> Result<Option<f64>, IndicatorError>;
|
|
|
|
/// Get the current value without updating
|
|
fn current(&self) -> Option<f64>;
|
|
} |