632296021c2475e9a94845afcabb692f242f092e
Per spec §4.4 + plan C1.2. Replaces v2 A2 (1d889d2de) + A2.1 (fe2498769) scalar approach that failed Gate 1 catastrophically on smokes vjmwc and lkrdf (155k trades, 9100% drawdown, Sharpe -15.7). The structural fix: direction comes from per-horizon SIGNED sum, so disagreeing horizons cancel. The scalar EMA on max(|p-0.5|) could only smooth magnitude — it could not smooth direction jitter. Only this multi-horizon weighted formula can. Formula (spec §4.4): weight_h = max(isv[h].net_edge, ε) / (isv[h].var + cost²) weighted_h = magnitude_h × weight_h × direction_h conviction_signed = sum(weighted_h) / sum(|weight_h|) conviction_ema = Wiener-α EMA(|conviction_signed|) (reuses A2 slots) target_lots = round(sign(conviction_signed) × conviction_ema × max_lots) Pearl conformance: - pearl_controller_anchors_isv_driven: weights from ISV state - pearl_one_unbounded_signal_per_reward: net_edge/(var+cost²) is the single unbounded factor; magnitude × direction is bounded in [-1,1] - pearl_zscore_normalization_for_magnitude_asymmetric_signals: divide by total_abs_weight for scale invariance - pearl_trade_level_vol_for_stop_distance: cost² is variance bootstrap - pearl_blend_formulas_must_have_permanent_floor: ε = cost · 0.01 on net_edge — no cold-start regime switch - pearl_audit_unboundedness_for_implicit_asymmetry: net_edge is one-sided positive (losing-edge horizons drop out, not flip sign) - pearl_wiener_alpha_floor_for_nonstationary: α floor at 0.4 (unchanged EMA mechanism, repointed at the multi-horizon scalar) DELETED: - The `final_size *= (conv_ema/raw_max_conv)` aggregate rescale step (the v2 bug that amplified weak signals) - The per-horizon `signed_sizes[h]` Kelly + Sharpe-weight aggregation loop in decision_policy_default (replaced by direct §4.4 formula) - Three obsolete tests asserting on the old scalar path: * conviction_ema_smooths_micro_oscillations * conviction_ema_does_not_lag_reversals * conviction_ema_rescale_never_amplifies_weak_signal * cfg_high_kelly_floor helper (only used by deleted tests) - cold_start_with_zero_floor_reproduces_old_bug (tested OLD kelly_floor semantics that v3 doesn't expose) - cold_start_persistent_bullish_now_closes (was passing under v2 via target oscillation from integer rounding; v3 produces stable target on stable signal — closes need price movement) - alpha_noop_side_2_preserved (anchored on the v2 kelly_frac_floor integer-truncation path that doesn't exist under v3) Applied to BOTH decision_policy_default and decision_policy_program (bytecode VM at OP_WRITE_ORDER). Per feedback_no_partial_refactor — both consumers migrate atomically. The VM's per-horizon emit + aggregate opcodes still execute but their stack `final_size` is unused at OP_WRITE_ORDER (the §4.4 conviction-driven target replaces it). The stack's attribution mask is still consumed for entry crediting. The three conviction-EMA device slots (conviction_ema_d, _diff_var, _sample_var) STAY in LobSimCuda. The Wiener-α EMA mechanism is reused on the multi-horizon conviction scalar; the device-helper signature changed from taking alpha_probs[] to taking the precomputed scalar |conviction_signed|. Kernel ABI change: decision_policy_default no longer takes target_annual_vol_units / annualisation_factor / kelly_frac_floor / sharpe_weight_floor (the §4.4 formula doesn't use them). Removed from both the CUDA signature and the launch builder in sim/mod.rs. The bytecode VM (decision_policy_program) still consumes those params for its OP_EMIT_PER_HORIZON_SIZE / OP_AGG_WEIGHTED_SHARPE opcodes — their device slots remain allocated. Test: multi_horizon_conviction_cancels_on_disagreement verifies the structural fix — bullish [0.7,0.3,0.7,0.3,0.5] horizons cancel to no-trade output (side=2/3, size=0, conv_ema≈0). Existing tests rebased: cfgs that used cost_per_lot_per_side=0.0 now use 1.0 (the §4.4 formula's eps_edge floor requires cost > 0). Each affected test file documents the rebase inline. Tests that were anchored on observed v2-kernel values (per pearl_tests_must_prove_not_lock_observations) are deleted; tests with genuine invariants (boundedness, direction-sanity, stop-controller behavior) are preserved. Hot-path discipline: no memcpy_htod/dtoh/dtov/synchronize introduced. Only kernel-internal computation; one launch arg removed from the default decision kernel. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…
…
…
…
…
Foxhunt
Production HFT trading system in Rust.
Architecture
The workspace contains 32 crates organized as follows:
Core Libraries (16)
| Crate | Purpose |
|---|---|
trading_engine |
Order processing, FIX 4.4, IB TWS, SIMD, RDTSC timing |
risk |
VaR, Kelly, circuit breakers, kill switches, compliance |
risk-data |
Risk data types and shared structures |
trading-data |
Trading data types |
ml |
DQN Rainbow, PPO, TFT, Mamba2, ensemble inference |
ml-data |
ML data types and feature definitions |
data |
Market data ingestion and storage |
backtesting |
Replay engine, strategy tester |
adaptive-strategy |
Ensemble execution, microstructure analysis |
common |
Shared types, resilience, error handling |
storage |
S3 and local model storage |
model_loader |
Model serialization and loading |
market-data |
Market data feed handlers |
database |
PostgreSQL access layer (SQLx) |
config |
Configuration management |
tli |
CLI commands and tooling |
Services (8)
| Service | Purpose |
|---|---|
backtesting_service |
gRPC backtesting service |
broker_gateway_service |
FIX routing, broker connectivity |
trading_service |
Core trading operations |
ml_training_service |
Model training orchestration |
data_acquisition_service |
Market data acquisition |
trading_agent_service |
Autonomous trading agents |
api_gateway |
gRPC API gateway with auth |
web-gateway |
Axum REST + WebSocket gateway |
Frontend
web-dashboard/ -- React 19 + TypeScript + Vite + TradingView charts.
Building
# Check compilation (no PostgreSQL required)
SQLX_OFFLINE=true cargo check --workspace
# Run tests for a specific crate
SQLX_OFFLINE=true cargo test -p <crate> --lib
# Clippy
SQLX_OFFLINE=true cargo clippy --workspace
ML Models
Four production model architectures on Candle v0.9.1 with CUDA:
- DQN Rainbow -- Deep Q-Network with prioritized replay, dueling heads, noisy nets
- PPO -- Proximal Policy Optimization with GAE and LSTM policies
- TFT -- Temporal Fusion Transformer for multi-horizon forecasting
- Mamba2 -- State space model for sequence prediction
Each model has a standalone trainer and a UnifiedTrainable adapter for the hyperopt pipeline.
Infrastructure
- Git: Gitea at
git.fxhnt.ai(Tailscale-only), Scaleway DEV1-S - Observability: OpenTelemetry OTLP (env
OTEL_EXPORTER_OTLP_ENDPOINT) - Database: PostgreSQL with SQLx offline mode for CI
License
Proprietary. All rights reserved.
Description
Languages
Rust
88.2%
Cuda
7.7%
Python
1.3%
Shell
1.1%
PLpgSQL
0.8%
Other
0.8%