Skip to main content

opendeviationbar_core/intrabar/
mod.rs

1//! Intra-bar features computed from constituent aggTrades.
2//!
3//! Issue #59: Intra-bar microstructure features for large open deviation bars.
4//!
5//! This module computes 22 features from trades WITHIN each open deviation bar:
6//! - 8 ITH features (Investment Time Horizon from trading-fitness algorithms)
7//! - 12 statistical features (OFI, intensity, burstiness, Kyle lambda, etc.)
8//! - 2 complexity features (Hurst exponent, permutation entropy)
9//!
10//! ## Key Design: Intra-Bar, Not Lookback
11//!
12//! Features are computed from trades **WITHIN** each bar (from `open_time` to
13//! `close_time`), NOT from a rolling lookback window before the bar opens.
14//! This ensures:
15//! - Temporal integrity: Features describe the bar itself
16//! - No extra memory: Trades already accumulated during bar construction
17//! - Consistent semantics: Features = bar characteristics
18//!
19//! ## ITH Algorithm Origin
20//!
21//! The ITH (Investment Time Horizon) algorithms are copied from:
22//! `trading-fitness/packages/metrics-rust/src/ith.rs`
23//!
24//! Key implementation notes:
25//! 1. **Exact algorithm alignment** with trading-fitness
26//! 2. **TMAEG = max_drawdown/max_runup**: No magic numbers, derived from window extremes
27//! 3. **Normalization**: Exact functions from `ith_normalize.rs`
28//! 4. **CV calculation**: Numba-aligned method with epoch_indices starting at 0
29
30pub mod drawdown;
31pub mod features;
32pub mod ith;
33pub mod normalize;
34pub mod normalization_lut;
35pub mod types;
36
37// Re-export main types and functions
38pub use features::{IntraBarConfig, IntraBarFeatures, compute_intra_bar_features, compute_intra_bar_features_with_scratch, compute_intra_bar_features_with_config};
39pub use types::{BearIthResult, BullIthResult};