work on new engine
This commit is contained in:
parent
44476da13f
commit
a1e5a21847
126 changed files with 3425 additions and 6695 deletions
40
apps/stock/engine/src/indicators/mod.rs
Normal file
40
apps/stock/engine/src/indicators/mod.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// 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>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue