- Add debug_assert_eq! guards in 4 train_baseline functions to catch
bar/feature length misalignment at debug time (#4)
- Remove "last sample targets itself" block in hyperopt PPO adapter
that created ~0 return sample biasing toward HOLD (#5)
- Align hyperopt state_dim 54→51 and num_actions 45→3 to match
train_baseline architecture, making tuned hyperparams transferable (#6)
- Use greedy_action() in evaluate_baseline PPO eval for deterministic results
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Three critical PPO fixes:
1. Add PPO::act_with_log_prob() returning (action, log_prob, value).
The existing act() discarded the policy log-probability, making
PPO importance sampling use wrong ratios during training.
2. Cap trajectory length with --max-steps-per-epoch in train_baseline
PPO path. DQN already had this limit; PPO iterated all features
(~500K per fold), causing OOM on 4GB GPU.
3. Replace random actions and fake log_prob/value in hyperopt PPO
adapter with real agent.act_with_log_prob() calls. Trajectories
now reflect actual policy behavior for meaningful hyperopt.
Also adds warmup offset alignment to PPO trajectory collection
(matching the DQN fix) and fixes .unwrap() in test.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PPO hyperopt: Split DATA 80/20 for train/val (not trajectory count).
Previously indexed training_data[..num_trajectories] which was only
16 samples from 56K — causing num_batches=0 and NaN from 0/0 division.
Now properly splits data array and uses min(64, num_train) for batch
episodes with ceil division for batch count.
DQN: Fix hardcoded "45 actions" in diagnostic log (now uses actual
q_vec.len()). Replace indexed[..top_n] slice with .take(top_n)
iterator to prevent potential slice panic.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Databento data pipeline stored files as .dbn.zst in symbol subdirectories
(e.g., ES.FUT/ES.FUT_2024-Q1.dbn.zst), but the hyperopt adapters and DQN
data loader only matched .dbn extension and used flat directory listing.
Three fixes:
- Match both .dbn and .dbn.zst file extensions in collect_dbn_files_recursive
- Use recursive directory traversal instead of flat read_dir
- Branch on extension to use Decoder::from_zstd_file() for .dbn.zst files
(from_file() doesn't handle zstd decompression)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7-gate conviction system, autonomous feedback loop with kill switch,
and Rust-native model registry — backed by PostgreSQL + QuestDB.
Resolve merge conflicts in hyperopt/adapters/mod.rs and enhanced_ml.rs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Scale model_memory_mb by activation_multiplier in resolve_batch_size()
so TFT (2.5x) gets proportionally smaller batches than DQN (1.0x)
- Add cached_capabilities() with OnceLock to avoid spawning nvidia-smi
on every call to CampaignConfig::dqn_default/ppo_default/PpoTrainer::new
- Add PartialEq to GpuCapabilities and simplify serde roundtrip test
- Update stale "RTX 3050 Ti" and "Exceeds GPU limit (230)" comments
to reflect dynamic detection
- Document Auto variant silent CPU fallback behavior (no callers affected)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hardcoded max_batch_size: 230 in CampaignConfig::dqn_default()
and ppo_default() with dynamic GPU detection via GpuCapabilities::detect()
and resolve_batch_size(). Update test to no longer assert <= 230.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- NoiseScheduler: precomputed cosine/linear alpha_bar schedules
- Denoiser: FC network with sinusoidal time embedding + SiLU + residual
- DDIMSampler: deterministic fast sampling (10 steps from 1000 timesteps)
- DiffusionTrainableAdapter: UnifiedTrainable for unified training pipeline
- Hyperopt adapter with ParameterSpace (9 params, batch ≤64 for 4GB GPU)
- ModelType::Diffusion registered in common + coordinator
- 41 tests passing (config=3, noise=7, denoiser=4, sampler=5, trainable=12, hyperopt=7)
- OOM-safe: FC denoiser instead of U-Net, small hidden dims, conservative defaults
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase 2-3 of ensemble expansion:
- KAN (Kolmogorov-Arnold Network): B-spline basis, layer, network, trainable adapter
- TLOB UnifiedTrainable adapter with 3D input support (batch, seq, features)
- Hyperopt adapters for both KAN and TLOB (ParameterSpace + metrics)
- ModelType::KAN variant registered in common, coordinator, lib.rs
- 44 new tests, all passing, zero warnings
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix leftover conflict markers from rebase onto main. Align as_str()
with main's semantics (general-purpose model names), add separate
s3_prefix() for S3 storage paths, and fix to_db_string() to preserve
per-variant database values.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Consolidate 4 separate ModelType enum definitions (ml 15 variants,
model_loader 7, campaign 2, job_spawner 4) into a single canonical
definition in common/src/model_types.rs with the union of all variants
and all methods (file_extension, as_str, to_db_string, weight, from_str,
Display).
- ml/src/lib.rs: replace 15-variant enum with re-export
- model_loader/src/lib.rs: replace 7-variant enum with re-export,
update PascalCase names (Dqn->DQN, Tft->TFT, etc)
- ml/hyperopt/campaign.rs: replace 2-variant enum with re-export
- services/ml_training_service/job_spawner.rs: replace 4-variant enum
with re-export, MAMBA2->MAMBA
- Remove orphan impl ToString in ml/observability/metrics.rs (Display
now provided by canonical type)
- Update backtesting_service and model_loader tests for new names
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Removed 3 duplicate ModelType enums (model_loader, hyperopt campaign,
job_spawner). Canonical definition in ml/src/lib.rs with 15 variants.
model_loader and job_spawner now re-export from ml. Added as_str(),
s3_prefix(), Display, to_db_string(), and weight() to canonical enum.
Replaced conflicting ToString impl with Display. Fixed variant name
mismatches (Dqn->DQN, Mamba2->MAMBA, Liquid->LNN, TlobTransformer->TLOB).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Delete 22 orphaned files (.backup, .broken_backup, .old, .rej, .disabled)
- Remove duplicate KillSwitch stub from risk_engine.rs, use AtomicKillSwitch
- Deduplicate UnixSocketKillSwitch via re-export from unix_socket module
- Rename StreamingConfig → EventStreamingConfig to resolve naming collision
- Guard MockTradingRepository behind #[cfg(test)] in trading_service
- Replace adaptive-strategy EnsembleConfig with re-export from ml crate
- Merge error_recovery.rs fields into canonical RetryConfig (circuit breaker,
jitter, HFT precision mode) and delete the 328-line dead module
- Replace local 3-variant RiskError with risk::error::RiskError import
- Fix all RetryConfig struct literals with ..Default::default()
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- emergency_stop: delegates to TradingServiceKillSwitch.emergency_shutdown()
which activates the global AtomicKillSwitch; returns Status::unavailable
when kill_switch_system is None rather than silently succeeding
- validate_order: reads max_order_quantity from config repository (falls back
to 1_000_000); additionally calls RiskEngine.check_var_limit() for VaR
validation when symbol and price are provided
- get_va_r: uses RiskEngine.calculate_marginal_var() for real VaR with a
parametric fallback; per-symbol marginal VaRs computed individually
- get_risk_metrics: derives portfolio_var_1d from RiskEngine; scales to 5d
and 30d via sqrt-of-time rule; remaining fields (Sharpe, beta, alpha,
current_drawdown) keep placeholder values with explicit TODO comments
- fix(risk): correct stop_monitoring() self.error_rate() → self.get_health_metrics()
(pre-existing typo that blocked compilation of trading_service)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CampaignResults with serde serialization. run_campaign() orchestrates
ArgminOptimizer for DQN hyperopt, saves best_params.json and
campaign_summary.json to timestamped results directory.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ObjectiveMode enum (EpisodeReward/Sharpe) to DQNTrainer and a
TwoPhaseObjective trait + optimize_two_phase() method to ArgminOptimizer.
Phase A optimizes episode reward for fast convergence, Phase B (pending
model Clone support) refines with Sharpe ratio. This keeps the static
extract_objective trait method untouched by separating objective switching
into instance-level state.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add load_ofi_features() helper to both DQN and PPO trainer adapters
that loads MBP10 snapshots from a sibling mbp10/ directory, computes
8-slot OFI feature vectors via OFICalculator, and overlays them onto
positions 43-50 of the training feature arrays. Gracefully falls back
to zero-padded features when MBP10 data is not available.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add use_qr_dqn, num_quantiles, qr_kappa fields to DQNHyperparameters
and pass them from DQNParams (hyperopt) through to DQNConfig (agent),
replacing hardcoded IQN values in the trainer.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add num_quantiles and qr_kappa to the continuous search space for
Quantile Regression DQN, replacing the disabled C51 distributional RL
(BUG #36). QR-DQN is enabled by default with 32 quantiles and kappa=1.0.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace flat read_dir() with recursive collect_dbn_files_recursive() in
both DQN and PPO hyperopt adapters so .dbn files inside symbol
subdirectories (6E.FUT/, ES.FUT/, NQ.FUT/, ZN.FUT/) are discovered
automatically.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replaces the TODO stub with a working Hyperband implementation that
applies Successive Halving pruning only at rung epochs (max_resource/eta^k).
Between rungs, trials always continue. Adds two tests verifying pruning
at rung epochs and non-pruning between rungs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Implement load_from_dbn() for both PPO and DQN hyperopt adapters
using dbn::DbnDecoder (same pattern as RealDataLoader)
- Fix PPO feature extraction: [f64;51] → [f32;54] with zero-padded
portfolio state (was silently dropping all samples due to len==54 check)
- Add NaN/Inf → 1e6 penalty in optimizer for non-finite objectives
- Fix partial_cmp().unwrap() panic when comparing NaN objectives
- Add ensemble real-model validation test (DQN + PPO trained on
real 6E.FUT data, predictions aggregated through ensemble)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add accumulation_steps config to PPOConfig with gradient accumulation
in update_mlp() using existing accumulate_grads/scale_grads utilities
- Add clip_epsilon_high: Option<f32> for asymmetric PPO clipping to
prevent entropy collapse during long training
- Rename WorkingPPO → PPO for consistency with DQN naming convention
- Add pub type WorkingPPO = PPO for backward compatibility
- Fix PPOConfig struct literals in trading_service and hyperopt adapter
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Created ml/src/types/ohlcv.rs as the single source of truth for OHLCVBar
(DateTime<Utc> timestamp, f64 OHLCV fields). Replaced all 13 duplicate
definitions across features/, regime/, real_data_loader, and evaluation/
with imports from crate::types::OHLCVBar.
Key changes:
- New: ml/src/types/mod.rs + ohlcv.rs with canonical OHLCVBar
(derives: Debug, Clone, Copy, PartialEq, Serialize, Deserialize + Default)
- Renamed: evaluation::metrics::OHLCVBar → OHLCVBarF32 (genuinely
different type: f32 fields, i64 timestamp for compact backtesting)
- Eliminated all import aliases (ExtractionOHLCVBar, RegimeOHLCVBar,
PriceOHLCVBar, VolumeOHLCVBar) in dbn_sequence_loader.rs and pipeline.rs
- Renamed regime::orchestrator::Bar → OHLCVBar (same fields, just aliased)
- Updated 39 files total (13 definitions removed, imports normalized)
1883 lib tests passing, compilation clean.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Delete lib_test.rs (no mod declaration — true orphan)
- Delete dqn/tests/factored_integration_tests.rs (not declared in tests/mod.rs)
- Delete hyperopt/adapters/tests/ (not declared in adapters/mod.rs)
- Delete integration_test.rs, test_common.rs, test_fixtures.rs (declared
in lib.rs but had zero imports — dead code that compiles but nobody uses)
- Inline test symbol data that was pulled from test_fixtures
- Remove include!("tests/dqn_wave26_params_test.rs") from hyperopt dqn adapter
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements critical P0.1 gap from DQN 2025 upgrade roadmap to address
overfitting in hyperopt/trainer by enabling proper weight decay in AdamW.
Changes:
- Add weight_decay field to DQNHyperparameters (default: 1e-4)
- Wire weight_decay to AdamW via Decay::DecoupledWeightDecay at 3 optimizer
initialization points in agent.rs
- Expand hyperopt search space to 40D with weight_decay [1e-5, 1e-3] log scale
- Update from_continuous(), to_continuous(), param_names() for roundtrip
This enables the modern best practice of decoupled weight decay (AdamW paper)
which prevents co-adaptation of network weights and improves generalization.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>