velora_ta/
lib.rs

1//! # velora-ta
2//!
3//! Technical Analysis indicators library for algorithmic trading.
4//!
5//! This is a standalone technical analysis library that can be used independently
6//! or as part of the Velora HFT platform. It provides a comprehensive collection
7//! of technical indicators organized by category.
8//!
9//! ## Features
10//!
11//! - **Trend Indicators**: SMA, EMA, WMA, DEMA, TEMA, HMA
12//! - **Momentum Indicators**: RSI, MACD, Stochastic, ROC, CCI
13//! - **Volatility Indicators**: ATR, Bollinger Bands, Keltner Channels, StdDev
14//! - **Volume Indicators**: OBV, VWAP, ADL, MFI, CMF
15//! - **Composite Tools**: Indicator chains, crossovers, threshold detection
16//!
17//! ## Design Philosophy
18//!
19//! - **Streaming-first**: Process data one point at a time for real-time trading
20//! - **Batch support**: Calculate historical indicator values efficiently
21//! - **Zero-copy**: Efficient with slices and references where possible
22//! - **Type-safe**: Compile-time guarantees via Rust's type system
23//! - **Well-tested**: Comprehensive test coverage with edge cases
24//!
25//! ## Quick Start
26//!
27//! ```ignore
28//! use velora_ta::{SMA, EMA, RSI, SingleIndicator};
29//! use chrono::Utc;
30//!
31//! // Create indicators
32//! let mut sma = SMA::new(20)?;
33//! let mut ema = EMA::new(10)?;
34//! let mut rsi = RSI::new(14)?;
35//!
36//! // Stream mode: process prices one at a time
37//! for price in prices {
38//!     let timestamp = Utc::now();
39//!
40//!     if let Some(sma_val) = sma.update(price, timestamp)? {
41//!         println!("SMA(20): {:.2}", sma_val);
42//!     }
43//!
44//!     if let Some(rsi_val) = rsi.update(price, timestamp)? {
45//!         if rsi_val > 70.0 {
46//!             println!("Overbought!");
47//!         } else if rsi_val < 30.0 {
48//!             println!("Oversold!");
49//!         }
50//!     }
51//! }
52//!
53//! // Or use batch mode for historical data
54//! let sma = SMA::new(20)?;
55//! let values = sma.calculate(&historical_prices)?;
56//! ```
57//!
58//! ## Indicator Categories
59//!
60//! ### Trend Indicators
61//!
62//! Track the direction and strength of price trends:
63//! - **SMA**: Simple Moving Average - equal-weighted average
64//! - **EMA**: Exponential Moving Average - more weight on recent prices
65//! - **WMA**: Weighted Moving Average - linear weights (planned)
66//! - **HMA**: Hull Moving Average - very responsive (planned)
67//!
68//! ### Momentum Indicators
69//!
70//! Measure the speed and magnitude of price changes:
71//! - **RSI**: Relative Strength Index - overbought/oversold detector
72//! - **MACD**: Moving Average Convergence Divergence - trend + momentum (in progress)
73//! - **Stochastic**: Oscillator comparing close to high-low range (planned)
74//!
75//! ### Volatility Indicators (Planned)
76//!
77//! Measure price volatility and potential ranges:
78//! - **ATR**: Average True Range - for stop-loss placement
79//! - **Bollinger Bands**: Volatility bands around price
80//! - **Keltner Channels**: ATR-based channels
81//!
82//! ### Volume Indicators (Planned)
83//!
84//! Analyze volume patterns:
85//! - **OBV**: On-Balance Volume - cumulative volume
86//! - **VWAP**: Volume-Weighted Average Price - intraday benchmark
87//! - **MFI**: Money Flow Index - RSI with volume
88//!
89//! ## Usage Patterns
90//!
91//! ### Streaming Mode (Real-time)
92//!
93//! ```ignore
94//! let mut indicator = SMA::new(20)?;
95//!
96//! // Process live data
97//! loop {
98//!     let price = get_latest_price();
99//!     let timestamp = Utc::now();
100//!
101//!     if let Some(value) = indicator.update(price, timestamp)? {
102//!         make_trading_decision(value);
103//!     }
104//! }
105//! ```
106//!
107//! ### Batch Mode (Historical)
108//!
109//! ```ignore
110//! let indicator = SMA::new(20)?;
111//! let prices = load_historical_data();
112//! let values = indicator.calculate(&prices)?;
113//!
114//! for (i, value) in values.iter().enumerate() {
115//!     if let Some(v) = value {
116//!         println!("Price: {}, SMA: {}", prices[i], v);
117//!     }
118//! }
119//! ```
120//!
121//! ## Standalone Usage
122//!
123//! This library can be used completely independently of the Velora platform:
124//!
125//! ```toml
126//! [dependencies]
127//! velora-ta = "0.1"
128//! ```
129
130#![warn(missing_docs)]
131#![warn(missing_debug_implementations)]
132#![warn(rust_2018_idioms)]
133
134pub mod errors;
135pub mod traits;
136pub mod types;
137pub mod utils;
138
139// Indicator implementations
140pub mod momentum;
141pub mod trend;
142pub mod volatility;
143pub mod volume;
144
145// Advanced modules
146pub mod patterns;
147pub mod statistical;
148pub mod williams;
149
150// Re-export core types and traits
151pub use errors::{IndicatorError, IndicatorResult};
152pub use traits::{Indicator, MultiIndicator, SingleIndicator, VolumeIndicator};
153pub use types::{IndicatorValue, MultiIndicatorValue, PriceType};
154pub use utils::CircularBuffer;
155
156// Re-export trend indicators for convenience
157pub use trend::{
158    Aroon, ParabolicSAR, SuperTrend, Vortex, ADX, DEMA, EMA, HMA, KAMA, SMA, SMMA, TEMA, VWMA, WMA,
159};
160
161// Re-export momentum indicators for convenience
162pub use momentum::{Momentum, Stochastic, WilliamsR, CCI, MACD, ROC, RSI, TSI};
163
164// Re-export volatility indicators for convenience
165pub use volatility::{BollingerBands, DonchianChannels, KeltnerChannels, StdDev, TrueRange, ATR};
166
167// Re-export volume indicators for convenience
168pub use volume::{ForceIndex, AD, CMF, EMV, MFI, OBV, VWAP};
169
170// Re-export Bill Williams indicators
171pub use williams::{Alligator, AwesomeOscillator, Fractals};
172
173// Re-export statistical indicators
174pub use statistical::{Correlation, LinearRegression, ZScore};
175
176// Re-export pattern detectors
177pub use patterns::{
178    BearishEngulfing, BullishEngulfing, Doji, Hammer, PatternDetector, PatternSignal, ShootingStar,
179    ThreeBlackCrows, ThreeWhiteSoldiers,
180};
181
182// Re-export types
183pub use types::OhlcBar;