rusty_backtest/
lib.rs

1#![allow(clippy::needless_range_loop)]
2
3//! L2 Backtesting Framework for HFT/MFT strategies
4//!
5//! A high-performance backtesting engine with realistic order matching,
6//! latency simulation, and conservative modeling for harsh market conditions.
7
8use rust_decimal::Decimal;
9
10// External crate re-exports
11pub use rustc_hash::{FxHashMap, FxHashSet};
12
13// Module declarations
14pub mod adapters; // NEW: Exchange data adapters
15pub mod engine;
16pub mod features; // NEW: Advanced microstructural features
17pub mod latency;
18pub mod matching;
19pub mod orderbook;
20pub mod parallel;
21pub mod simd_enhanced; // NEW: Enhanced SIMD operations for HFT
22
23#[cfg(test)]
24mod tests;
25
26// Re-export key types from submodules
27pub use adapters::{
28    BinanceTardisAdapter, KrxA3B6G7Adapter, KrxA3B6G7Event, KrxA3B6G7Iterator, TardisL2Event,
29    TardisL2Iterator,
30}; // NEW
31pub use engine::{BacktestConfig, BacktestEngine, Event, MarketDataEvent, OrderEvent, Strategy};
32pub use features::{FeatureCalculator, MicrostructuralFeatures, OrderBookSnapshot, TradeTick}; // NEW
33pub use latency::{FixedLatency, GaussianLatency, LatencyModel, UniformLatency};
34pub use matching::{
35    ConservativeParams, Execution, MarketImpact, MatchingEngine, Order, OrderSide, OrderType,
36    QueueModel,
37};
38pub use orderbook::{Level, OrderBook};
39pub use parallel::{
40    MarketDataProvider, ParallelConfig, ParallelEngine, ParallelStrategy, SymbolConfig,
41};
42pub use simd_enhanced::{EnhancedSimdOps, SimdAlignedBuffer}; // NEW: Enhanced SIMD operations
43
44/// The result of a backtest.
45#[derive(Debug, Clone)]
46pub struct BacktestResult {
47    /// A vector of executions that occurred during the backtest.
48    pub executions: Vec<Execution>,
49    /// The final profit and loss of the backtest.
50    pub final_pnl: Decimal,
51    /// The maximum drawdown of the backtest.
52    pub max_drawdown: Decimal,
53    /// The Sharpe ratio of the backtest.
54    pub sharpe_ratio: f64,
55    /// The total volume traded during the backtest.
56    pub total_volume: Decimal,
57    /// The total number of trades executed during the backtest.
58    pub trade_count: u64,
59}
60
61/// Prelude module for convenient imports of commonly used types and traits.
62///
63/// This module provides a convenient way to import all essential types needed for backtesting,
64/// including engines, strategies, order types, and configuration structures.
65pub mod prelude {
66    pub use crate::engine::{
67        BacktestConfig, BacktestEngine, Event, MarketDataEvent, OrderEvent, Strategy,
68    };
69    pub use crate::latency::{FixedLatency, GaussianLatency, LatencyModel, UniformLatency};
70    pub use crate::matching::{
71        ConservativeParams, Execution, MarketImpact, MatchingEngine, Order, OrderSide, OrderType,
72        QueueModel,
73    };
74    pub use crate::orderbook::{Level, OrderBook};
75    pub use crate::parallel::{
76        MarketDataProvider, ParallelConfig, ParallelEngine, ParallelStrategy, SymbolConfig,
77    };
78    pub use crate::{BacktestResult, FxHashMap, FxHashSet};
79}