Commit Graph

894 Commits

Author SHA1 Message Date
jgrusewski
d8d51aa2d0 fix(docker): add missing workspace members and SQLX_OFFLINE to all Dockerfiles
All 6 service Dockerfiles were missing newly-added workspace crates
(web-gateway, ctrader-openapi, foxhunt-deploy, broker_gateway_service),
causing cargo workspace resolution failures during Docker builds.

Changes across all Dockerfiles:
- Add COPY directives for web-gateway, ctrader-openapi, foxhunt-deploy,
  broker_gateway_service (new workspace members since Dockerfiles written)
- Add SQLX_OFFLINE=true env and .sqlx cache copy where missing
- Add perl and make system deps (needed for OpenSSL build from source)
- Remove COPY migrations (dir excluded by .dockerignore, not needed)
- Expand broker_gateway_service from 3-crate to full workspace copy

Validated: docker build --check passes all 6, cargo check -p passes all 6.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:46:24 +01:00
jgrusewski
fa4c649338 fix(ci): triage workflows — fix 3 essential, delete 6 duplicates
Essential workflow fixes:
- ci.yml: add SQLX_OFFLINE=true, replace fictitious cargo subcommands
  (test-unit, ci-lint, audit-deps, etc.) with real cargo commands,
  remove broken 9-way test matrix, remove instrument-coverage RUSTFLAGS
- test.yml: add SQLX_OFFLINE=true to build-check job, fix conflicting
  clippy flags (-D and -W on clippy::all), update JWT secret to 32+ chars
- compilation-guard.yml: add SQLX_OFFLINE=true, remove references to
  non-existent paths (services/trading-engine, crates/common/types),
  remove dangerous auto-commit-to-main, remove MIRI on missing packages

Deleted duplicates (justification):
- comprehensive_testing.yml: duplicate of comprehensive-testing.yml
  (same purpose, underscore vs hyphen naming)
- production-deploy.yml: duplicate of production-deployment.yml
  (both named "Production Deployment Pipeline", this one has stale paths)
- coverage-fixed.yml: duplicate of coverage.yml
  (uses deprecated actions-rs/toolchain@v1 and actions/cache@v3)
- performance.yml: duplicate of benchmark_regression.yml
  (both "Performance Regression Detection", this one less mature)
- quality-baseline.json: not a workflow, stale fake data (999 warnings)
- quality-metrics.json: not a workflow, stale fake data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:39:00 +01:00
jgrusewski
f81bd3fc2e test(trading_service): add E2E pipeline integration test (10 models)
Proves the critical trading pipeline path works end-to-end:
OHLCV -> features -> ensemble -> prediction. Uses all 10 real candle
inference adapters (DQN, PPO, TFT, Mamba2, Liquid-CfC, TGGN, TLOB,
KAN, xLSTM, Diffusion) with random weights, 60 synthetic OHLCV bars,
and asserts confidence/action/model-count invariants. No external
dependencies (no DB, no Docker).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:34:06 +01:00
jgrusewski
c8bc3504f0 feat(trading_service): wire market data feed to ensemble coordinator
Spawn a background tokio task that feeds synthetic OHLCV bars into the
ensemble coordinator's per-symbol feature extractors.  The extractors
require ~51 bars of warmup before they can produce real 51-dim feature
vectors; without this feed they remain cold and return zeros.

The task uses a random-walk price generator with realistic base prices
for the four baseline futures symbols (ES, NQ, ZN, 6E) and configurable
interval (MARKET_FEED_INTERVAL_MS, default 1s) and symbol list
(MARKET_FEED_SYMBOLS).  In production this will be replaced by a
Databento or exchange data feed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:20:02 +01:00
jgrusewski
2942a043ce Merge branch 'worktree-operational-maturity'
# Conflicts:
#	ml/src/ensemble/mod.rs
2026-02-23 16:02:03 +01:00
jgrusewski
1999e5ddbe feat(trading_service): wire all 10 ML models into ensemble coordinator
Register TGGN, TLOB, KAN, xLSTM, and Diffusion inference adapters
alongside the existing DQN, PPO, TFT, Mamba2, and Liquid-CfC.
Rebalance weights to 0.10 each (equal weighting across 10 models).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:55:11 +01:00
jgrusewski
6d43f8d8d2 feat(ml): add TLOB inference adapter for ensemble
Sequence-buffered adapter with 3-layer MLP projection
(flat_dim -> hidden -> hidden/2 -> 1). Ring buffer collects
seq_len feature vectors, returns neutral prediction until full,
then flattens and projects through the MLP with sigmoid output
mapping to direction [-1,1] and confidence [0,1].

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:51:06 +01:00
jgrusewski
7c4341600d feat(ml): add KAN inference adapter for ensemble
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:51:06 +01:00
jgrusewski
3a403669b7 feat(ml): add TGGN inference adapter for ensemble
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:51:06 +01:00
jgrusewski
bb5286e910 Merge branch 'feat/trading-universe-data-org' 2026-02-23 15:22:05 +01:00
jgrusewski
236e1665cf fix(ml): address code review findings
- Remove panic!() calls from test_futures_baseline_micro_mapping,
  use map()+Some() pattern consistent with rest of test suite
- Make DatasetSpec::from_universe() accept a name parameter instead
  of hardcoding "futures-baseline"
- Add doc comment to UniverseConfigMeta explaining dead_code fields

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:17:58 +01:00
jgrusewski
323b77c820 feat(ml): add manifest generation test — builds cache manifest from on-disk DBN files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:05:10 +01:00
jgrusewski
7e96d6e303 chore: add data/cache/ to .gitignore (downloaded market data)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 15:00:26 +01:00
jgrusewski
7b870726ab docs: add production pipeline wiring implementation plan (10 tasks)
Detailed TDD implementation plan for wiring all 10 ML models into
the ensemble coordinator. Covers 5 new inference adapters (KAN, TGGN,
xLSTM, TLOB, Diffusion), main.rs registration with equal weights,
market data wiring, E2E integration test, Docker/CI validation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:59:18 +01:00
jgrusewski
9d8622f410 feat: add futures-baseline universe config (TOML)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:57:48 +01:00
jgrusewski
6d844c009a feat(ml): add AssetUniverse::from_config() for TOML config loading
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:50:40 +01:00
jgrusewski
d268a9dca8 docs: add production pipeline wiring design (6 tasks)
Wire existing components into end-to-end pipeline: 5 missing inference
adapters, 10-model registration, market data feeding, integration test,
Docker build validation, and CI pipeline triage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:43:22 +01:00
jgrusewski
8ce2d53d21 feat(ml): add trading_symbol field to UniverseAsset for micro contract mapping
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:41:22 +01:00
jgrusewski
3a60f303e3 refactor(ml): unify AssetClass — re-export from asset_selection
Remove duplicate AssetClass enum from data_pipeline module and replace
with a re-export from asset_selection, which is now the canonical
location. This ensures data_pipeline::AssetClass and
asset_selection::AssetClass are the same type, enabling direct
comparison and preventing subtle type mismatch bugs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:36:36 +01:00
jgrusewski
ae225b0e31 docs: add trading universe & data organization implementation plan
10-task plan: unify AssetClass, add trading_symbol field, futures_baseline()
preset, TOML config loading, DatasetSpec::from_universe() wiring, data
reorganization into cache structure, stale data cleanup, manifest generation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:21:48 +01:00
jgrusewski
d4f4f72a50 Merge branch 'feature/operational-maturity'
# Conflicts:
#	ml/src/lib.rs
2026-02-23 14:20:23 +01:00
jgrusewski
66966806c7 docs: add trading universe & data organization design
Define futures baseline universe (ES, NQ, ZN, 6E) with micro
contract mapping for limited capital. Reorganize scattered test
data into cache structure. Download spec for 730 days of OHLCV-1m.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:17:22 +01:00
jgrusewski
3f9f6ebe17 fix(trading): fix QuestDB metrics provider for real integration testing
- Use tokio::task::block_in_place for safe sync→async bridging
- Replace count(*) with count(1) in division context (QuestDB parser bug)
- Add coalesce() for stddev NULL handling (single-row edge case)
- Consolidate integration tests into single lifecycle test with DROP+CREATE
- All 4 QuestDB tests pass against real QuestDB 8.2.3

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 14:13:19 +01:00
jgrusewski
69d435cb52 feat(trading): integrate QuestDB metrics provider for feedback loop
Replace stub metrics provider with real QuestDBMetricsProvider that
queries QuestDB via PostgreSQL wire protocol (port 8812) for rolling
model Sharpe, win rates, confidence buckets, and ensemble metrics.

- Add QuestDB service to docker-compose.yml (8.2.3, ports 9009/8812/9003)
- Create questdb_metrics.rs with 5 SQL queries and graceful fallback
- Wire QuestDBMetricsProvider into main.rs (replaces StubMetricsProvider)
- Fix unused Instant import in feedback_loop.rs (#[cfg(test)] scope)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:57:46 +01:00
jgrusewski
dc94c0a757 feat(trading): add feedback loop orchestrator and wire into service init
FeedbackLoop runs as a background tokio task, periodically running
weight and gate optimization cycles with kill switch monitoring and
retraining trigger detection. Wired into main.rs with a stub
MetricsProvider until QuestDB is deployed.

7 new tests covering kill switch, freeze/unfreeze, retraining triggers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:49:47 +01:00
jgrusewski
81ae71c88e feat(ml): export data_pipeline and asset_selection types in prelude
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:40:50 +01:00
jgrusewski
1b7f72a0d2 feat(ml,trading): add gate optimizer, model registry, and P&L attribution
Gate optimizer adjusts conviction gate thresholds based on win-rate per
confidence bucket with cooldown and kill switch safety rails. Model
registry provides lifecycle management (Candidate → Staging → Production
→ Archived) with InMemoryModelRegistry for testing. P&L attribution
decomposes realized trade P&L into per-model contributions using signal
alignment.

24 new tests across 3 modules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:39:22 +01:00
jgrusewski
1cc5a79365 feat(ml): add ActiveSetSelector for top-N asset selection by composite score
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:34:37 +01:00
jgrusewski
b94caf6d65 feat(ml): add PredictabilityScorer with rolling ML accuracy tracking
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:29:13 +01:00
jgrusewski
d2fe4c4e98 feat(ml): add asset_selection module with AssetUniverse config types
Introduces the asset_selection module with AssetClass enum (Equity/ETF/Future),
UniverseAsset struct, and AssetUniverse with filtering, lookup, and a us_starter()
preset of 7 highly liquid US assets. Includes scorer/selector placeholder stubs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:23:42 +01:00
jgrusewski
d623fb100c feat(ensemble): add autonomous weight optimizer with EMA Sharpe and safety rails
Adjusts model weights based on rolling Sharpe ratios with:
- EMA smoothing (alpha=0.1)
- Bounds: [0.05, 0.40] per model
- Max step: 0.03 per cycle
- 24h cooldown, 7-day grace period for new models
- Kill switch freeze/unfreeze
8 tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:18:53 +01:00
jgrusewski
766e16e724 feat(ml): add PreparedDataset with batch iterators for training
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:17:54 +01:00
jgrusewski
8106f4987b feat(common): add QuestDB client with ring buffer and health monitoring
Non-critical path: if QuestDB is unavailable, metrics buffer locally
(up to 10,000 entries) and flush when connection is restored.
Feature-gated under `questdb` feature. 6 tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:17:52 +01:00
jgrusewski
1b43d80db7 feat(ml): add DatasetManager for orchestrating data preparation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:12:33 +01:00
jgrusewski
aa67929ebc feat(ml): add cache manifest for tracking downloaded training data
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:05:52 +01:00
jgrusewski
ce8fd2b97e feat(ensemble): wire conviction gates into EnsembleCoordinator::predict()
Adds optional ConvictionGateEvaluator field to EnsembleCoordinator.
When configured, predict() evaluates all 7 gates before returning.
If any gate rejects, returns HOLD with rejection metadata.
Includes quorum ratio, trading session, and regime volatility helpers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 13:03:26 +01:00
jgrusewski
5bc56eb9c8 feat(ml): add data_pipeline module with DatasetSpec and DatasetMode types
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:54:36 +01:00
jgrusewski
948b2d8992 feat(ensemble): add 7-gate conviction system with evaluator and 15 tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:41:55 +01:00
jgrusewski
9f499282ac docs: add data pipeline & asset selection implementation plan
8-task plan across 3 phases: data pipeline (types, cache, manager,
prepared dataset), asset selection (universe, scorer, selector),
and integration wiring. 7 new files, ~51 tests estimated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:36:45 +01:00
jgrusewski
df251a9d7e docs: add data pipeline and asset selection design
Covers automated data downloading/caching for ML training and
a tiered asset selection funnel (universe → predictability → regime → signal).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:28:02 +01:00
jgrusewski
824aee3f21 feat(ensemble): add 7-gate conviction system with evaluator and 15 tests
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:24:36 +01:00
jgrusewski
f0bafdf30b docs: add operational maturity implementation plan (12 tasks, 6 phases)
Three pillars: 7-gate conviction system, autonomous feedback loop
with kill switch, Rust-native model registry. QuestDB analytics layer.
~55 tests, 7 new files planned across ml/ and trading_service/.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 12:11:28 +01:00
jgrusewski
abf4baf30e docs: add operational maturity system design (3 pillars)
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>
2026-02-23 12:02:52 +01:00
jgrusewski
4ab6975c38 fix(ml): wire activation_multiplier, cache GPU detection, fix stale comments
- 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>
2026-02-23 11:49:22 +01:00
jgrusewski
fd2221e50e feat(ml): export GPU types in prelude
Add DeviceConfig and GpuCapabilities re-exports to ml::prelude so
downstream crates can import GPU management types via a single
`use ml::prelude::*` statement.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:41:10 +01:00
jgrusewski
6425eb150b feat(ml): use dynamic GPU detection for hyperopt campaign batch sizes
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>
2026-02-23 11:40:27 +01:00
jgrusewski
0409ad38a0 feat(ml): replace hardcoded batch_size 230 with dynamic GPU detection in PPO trainer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:35:26 +01:00
jgrusewski
c0751eb61b refactor(ml): use DeviceConfig::Auto in ensemble adapters
Replace Device::cuda_if_available(0).unwrap_or(Device::Cpu) with
DeviceConfig::Auto.resolve().unwrap_or(Device::Cpu) in DQN, PPO, TFT,
and Mamba2 ensemble inference adapters so device selection goes through
the centralized GPU detection module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:30:17 +01:00
jgrusewski
aac8142284 feat(ml): NaN gradient detection with auto-halt during training
Add check_gradients_finite() to gradient_utils.rs that detects NaN/Inf
in GradStore before optimizer step. Uses efficient sum_all approach
where any NaN element produces a NaN sum. Includes 3 unit tests
(finite pass, NaN detected, empty vars pass).

DQN and PPO training loops already wired via gradient_accumulation
module's check_gradients_finite (all 6 paths: standard policy/value,
remainder policy/value, LSTM policy/value).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:30:01 +01:00
jgrusewski
6ffa38cc04 feat(ml): NaN gradient detection with auto-halt during training
Add check_gradients_finite() utility that scans GradStore for NaN/Inf
values. Wire into DQN (after gradient accumulation, before optimizer step)
and PPO (both MLP and LSTM training paths, after backward pass).

Prevents silent model corruption from exploding gradients or numerical
instability — training halts immediately with a descriptive error.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 11:26:49 +01:00