Files
foxhunt/crates/ml-backtesting/src/lib.rs
jgrusewski 1ca034e22f feat(ml-backtesting): policy tree + bytecode flatten
Strategy (recursive Leaf | Ensemble | Portfolio | RegimeSwitch) +
StrategyConfig (horizon_idx + sizing_policy + sl_tp_rules +
max_concurrent_lots). Strategy::default_for(max_lots) returns the v1
default: per-horizon adaptive Ensemble with WeightedByRealizedSharpe
aggregator. No static horizon mask — capital auto-shifts via per-horizon
ISV-Kelly recent_sharpe weights (see spec §5 + §6).

Strategy::flatten() walks the tree → linear bytecode Program
(repr(C) Pod Instruction { op, arg0, arg1, arg2 }, 8 bytes/instruction)
for upload to device-global memory at slot blockIdx.x. RegimeSwitch
emits BranchIfRegime chains with arg2 patched to the post-child jump
offset.

Tests cover: 5-horizon default tree shape, flatten output for default
+ single-leaf + 2-leaf Portfolio (verifying ApplyConflict op emission),
Instruction layout size pin (8 bytes), LatencyConfig default 100ms
(IBKR+Scaleway baseline), Empirical wrap-around + empty case,
Decomposed summation.

IsvKellyStateHost host-mirror of cuda IsvKellyState (24 bytes, Pod)
defined in policy::sizing for warm-start file I/O in later commits.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 08:15:07 +02:00

27 lines
1.3 KiB
Rust

//! ML Backtesting Framework
//!
//! Provides barrier parameter optimization, DQN action loading from CSV,
//! and comprehensive report generation for model evaluation.
// Workspace lints deny unwrap/expect/indexing at warn level; override to allow in tests only.
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing))]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::integer_division)]
#![allow(clippy::shadow_reuse, clippy::shadow_same, clippy::shadow_unrelated)] // Tensor ops: let x = x.relu() is idiomatic
#![allow(clippy::non_ascii_literal)] // Math symbols in ML documentation and error messages
#![allow(clippy::partial_pub_fields)] // ML config structs: some fields are pub API, some internal
#![allow(clippy::same_name_method)] // Intentional: inherent methods shadow trait defaults for ML-specific behavior
#![allow(clippy::indexing_slicing)] // Tensor/matrix indexing with bounds guaranteed by construction
pub use ml_core::MLError;
pub mod action_loader;
pub mod barrier_backtest;
pub mod order;
pub mod policy;
pub mod report;
pub use action_loader::{load_actions_from_csv, DQNActionRecord};
pub use barrier_backtest::{BacktestResults, BarrierBacktester, BarrierParams};
pub use report::{BacktestReport, PerformanceMetrics, Recommendation};