Skip to main content

opendeviationbar_core/
lib.rs

1//! Core open deviation bar processing algorithms
2//!
3//! Non-lookahead bias open deviation bar construction with temporal integrity guarantees.
4//!
5//! ## Features
6//!
7//! - Non-lookahead bias: Thresholds computed only from bar open price
8//! - Breach inclusion: Breaching trade included in closing bar
9//! - Fixed thresholds: Never recalculated during bar lifetime
10//! - Temporal integrity: Guaranteed correct historical simulation
11//! - **Cross-file checkpoints**: Seamless continuation across file boundaries (v6.1.0+)
12//! - **Arrow export**: Zero-copy streaming to Python via Arrow RecordBatch (v8.0.0+)
13
14// Issue #147 (Phase 9): Use Mimalloc for high-performance memory allocation
15// Expected 2-5x speedup on multithreaded workloads (entropy cache, trade accumulation)
16#[cfg(not(target_env = "msvc"))]
17#[global_allocator]
18static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
19
20pub mod checkpoint;
21pub mod entropy_cache_global; // Issue #145: Multi-symbol entropy cache sharing (Phase 1)
22pub mod errors;
23pub mod export_processor; // Export-oriented processor (extracted Phase 2d)
24pub mod fixed_point;
25pub mod interbar; // Issue #59: Inter-bar microstructure features (lookback window BEFORE bar)
26pub mod interbar_cache; // Issue #96 Task #144 Phase 4: Inter-bar feature result caching for streaming
27pub mod interbar_math; // Issue #59: Inter-bar math helpers (extracted Phase 2e) - public for profiling/benchmarking
28pub mod interbar_types; // Issue #59: Inter-bar type definitions (extracted Phase 2b)
29pub mod intrabar; // Issue #59: Intra-bar features (trades WITHIN bar)
30pub mod normalization_lut; // Issue #96 Task #197: Shared LUT optimization (sigmoid, tanh, CV sigmoid)
31pub mod processor;
32pub mod timestamp;
33pub mod trade; // Trade/DataSource types (extracted Phase 2c)
34pub mod types;
35
36// Arrow export (only available with arrow feature)
37#[cfg(feature = "arrow")]
38pub mod arrow_export;
39
40// Test utilities (only available in test builds or with test-utils feature)
41#[cfg(any(test, feature = "test-utils"))]
42pub mod test_utils;
43
44#[cfg(any(test, feature = "test-utils"))]
45pub mod test_data_loader;
46
47/// Feature manifest TOML, embedded at compile time.
48/// SSoT for all microstructure feature metadata (Issue #95).
49/// Exposed to Python via PyO3 `get_feature_manifest_raw()`.
50pub const FEATURE_MANIFEST_TOML: &str = include_str!("../data/feature_manifest.toml");
51
52// Re-export commonly used types
53pub use checkpoint::{AnomalySummary, Checkpoint, CheckpointError, PositionVerification};
54pub use entropy_cache_global::{
55    GLOBAL_ENTROPY_CACHE_CAPACITY, create_local_entropy_cache, get_global_entropy_cache,
56}; // Issue #145: Global entropy cache API
57pub use fixed_point::FixedPoint;
58pub use interbar::{InterBarConfig, InterBarFeatures, LookbackMode, TradeHistory, TradeSnapshot};
59pub use interbar_cache::{INTERBAR_FEATURE_CACHE_CAPACITY, InterBarCacheKey, InterBarFeatureCache}; // Issue #96 Task #144 Phase 4: Inter-bar feature result cache API
60pub use interbar_math::EntropyCache; // Issue #145 Phase 2: Export for external cache parameters
61pub use intrabar::{IntraBarConfig, IntraBarFeatures, compute_intra_bar_features};
62pub use processor::{ExportOpenDeviationBarProcessor, OpenDeviationBarProcessor, ProcessingError};
63pub use timestamp::{
64    create_aggtrade_with_normalized_timestamp, normalize_timestamp, validate_timestamp,
65};
66pub use types::{AggTrade, DataSource, OpenDeviationBar};
67
68// Arrow export re-exports (only available with arrow feature)
69#[cfg(feature = "arrow")]
70pub use arrow_export::{
71    ArrowImportError,
72    aggtrade_schema,
73    aggtrades_to_record_batch,
74    opendeviationbar_schema,
75    opendeviationbar_vec_to_record_batch,
76    // Issue #300 (MEM-02): Zero-copy Arrow iterator adapter
77    process_from_arrow_columns,
78    // Issue #88: Arrow-native input path
79    record_batch_to_aggtrades,
80};