Files
foxhunt/ml/WAVE2_COMPILATION_ERRORS.md
jgrusewski 989ad8485c feat(wave9-11): Complete 225-feature integration and service migration
Wave 9: Feature Integration (20 agents)
- Wire Wave D features into extraction pipeline (ml/src/features/extraction.rs:197-204)
- Reduce statistical features from 50 to 26 to make room for Wave D
- Update method signature to &mut self for stateful extractors
- Fix 7 division-by-zero bugs in feature extraction
- Train all 4 models (DQN, PPO, MAMBA-2, TFT) with 225 features
- Test pass rate: 99.2% (2,061/2,074 tests)

Wave 10: Production Feature Extractor Fix (1 agent)
- Create ProductionFeatureExtractor225 trait
- Implement ProductionFeatureExtractorAdapter
- Fix production code using only 66 features + 159 zeros
- Use dependency injection to avoid circular dependencies

Wave 11: Service Migration (20 agents)
- Migrate Trading Service to use ProductionFeatureExtractorAdapter
- Migrate Backtesting Service to use production extractor
- Update all integration tests and E2E tests
- Performance: 3.98μs/bar (22% faster than Wave 9)
- Test pass rate: 99.84% (1,239/1,241 tests)

Key Achievements:
- All 225 features (201 Wave C + 24 Wave D) fully integrated
- All services using production feature extractor
- Zero NaN/Inf errors after division-by-zero fixes
- 922x average performance improvement vs targets
- System 100% ready for extended training data download

Files Modified:
- ml/src/features/extraction.rs (Wave D wiring)
- ml/src/features/production_adapter.rs (NEW - adapter pattern)
- common/src/ml_strategy.rs (trait + dependency injection)
- services/trading_service/src/paper_trading_executor.rs
- services/backtesting_service/src/ml_strategy_engine.rs
- 18+ test files updated for &mut self pattern

Next Steps:
- Wave 12: Download 180 days Databento data (~$3.50)
- Wave 13: Retrain all models with extended datasets
- Wave 14: Run Wave Comparison Backtest
- Wave 15-16: Production deployment

🤖 Generated with Claude Code (Waves 9-11: 41 agents, 153 total)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-20 21:54:39 +02:00

344 lines
7.6 KiB
Markdown

# Wave 2 Compilation Errors - Detailed Analysis
**Date**: 2025-10-20
**Agent**: Wave 2 Agent 14
**Status**: 5 errors blocking Wave 3
---
## Root Cause Analysis
### Primary Issue: OHLCVBar Type Proliferation
Wave B introduced `alternative_bars::OHLCVBar` for bar sampling.
Wave D introduced two more `OHLCVBar` types:
- `regime_adx::OHLCVBar` (for ADX calculation)
- `extraction::OHLCVBar` (for regime adaptive features)
**Result**: 3 different `OHLCVBar` structs with similar names but incompatible types.
**Impact**: Cannot pass Wave B bar data to Wave D regime features without type conversion.
---
## Error Breakdown
### Error 1: Timestamp Type Mismatch
**File**: `ml/src/data_loaders/dbn_sequence_loader.rs:1266`
**Code**:
```rust
timestamp: 0, // Not used in feature calculation
```
**Issue**: Expected `DateTime<Utc>`, found `{integer}`
**Fix** (2 min):
```rust
timestamp: chrono::Utc::now(),
```
**Alternatively** (if timestamp is truly unused):
```rust
timestamp: chrono::Utc.timestamp_nanos(0),
```
---
### Error 2: OHLCVBar Type Mismatch (ADX Update)
**File**: `ml/src/data_loaders/dbn_sequence_loader.rs:1280`
**Code**:
```rust
let adx_features = self.regime_adx.update(&current_bar);
```
**Issue**: `current_bar` is `alternative_bars::OHLCVBar`, but `regime_adx.update()` expects `regime_adx::OHLCVBar`
**Fix Options**:
**Option A: Type Conversion Function** (Recommended, 10 min)
```rust
// Add to ml/src/features/regime_adx.rs
impl From<crate::features::alternative_bars::OHLCVBar> for OHLCVBar {
fn from(bar: crate::features::alternative_bars::OHLCVBar) -> Self {
Self {
timestamp: bar.timestamp,
open: bar.open,
high: bar.high,
low: bar.low,
close: bar.close,
volume: bar.volume,
}
}
}
// Usage:
let adx_features = self.regime_adx.update(&current_bar.into());
```
**Option B: Unify Types** (Complex, 30-60 min)
- Move `OHLCVBar` to `common/src/features/types.rs`
- Update all 3 modules to use shared type
- Requires extensive refactoring
**Option C: Type Alias** (Quick, 5 min, but less type-safe)
```rust
// In ml/src/features/regime_adx.rs
pub type OHLCVBar = crate::features::alternative_bars::OHLCVBar;
```
---
### Error 3: OHLCVBar Type Mismatch (Adaptive Features)
**File**: `ml/src/data_loaders/dbn_sequence_loader.rs:1298`
**Code**:
```rust
let adaptive_features = self.regime_adaptive.update(
regime,
&self.bar_buffer,
current_position,
);
```
**Issue**: `bar_buffer` is `Vec<alternative_bars::OHLCVBar>`, but `regime_adaptive.update()` expects `&[extraction::OHLCVBar]`
**Fix Options**:
**Option A: Conversion** (Recommended, 15 min)
```rust
// Add to ml/src/features/extraction.rs
impl From<crate::features::alternative_bars::OHLCVBar> for OHLCVBar {
fn from(bar: crate::features::alternative_bars::OHLCVBar) -> Self {
Self {
timestamp: bar.timestamp,
open: bar.open,
high: bar.high,
low: bar.low,
close: bar.close,
volume: bar.volume,
}
}
}
// Usage (in dbn_sequence_loader.rs):
let converted_bars: Vec<_> = self.bar_buffer.iter()
.map(|b| extraction::OHLCVBar::from(*b))
.collect();
let adaptive_features = self.regime_adaptive.update(
regime,
&converted_bars,
current_position,
);
```
**Option B: Unified Type** (Same as Error 2, Option B)
---
### Error 4: DBN Field Access (Line 586)
**File**: `ml/src/trainers/dqn.rs:586`
**Code**:
```rust
(ohlcv.ts_event / 1_000_000_000) as i64,
```
**Issue**: `OhlcvMsg` doesn't have direct `ts_event` field. It's nested in `hd.ts_event`.
**Fix** (1 min):
```rust
(ohlcv.hd.ts_event / 1_000_000_000) as i64,
```
---
### Error 5: DBN Field Access (Line 587)
**File**: `ml/src/trainers/dqn.rs:587`
**Code**:
```rust
(ohlcv.ts_event % 1_000_000_000) as u32,
```
**Issue**: Same as Error 4
**Fix** (1 min):
```rust
(ohlcv.hd.ts_event % 1_000_000_000) as u32,
```
---
## Recommended Fix Order
### Phase 1: Quick Fixes (5 min)
1. **Error 1**: Update timestamp to `Utc::now()` or `Utc.timestamp_nanos(0)`
2. **Error 4-5**: Add `.hd` to DBN field access
**Verification**:
```bash
cargo build -p ml --lib 2>&1 | grep "^error" | wc -l
# Expected: 2 errors remaining
```
---
### Phase 2: Type Conversions (20-30 min)
3. **Error 2**: Add `From<alternative_bars::OHLCVBar>` to `regime_adx::OHLCVBar`
4. **Error 3**: Add `From<alternative_bars::OHLCVBar>` to `extraction::OHLCVBar`
**Code Locations**:
- `/home/jgrusewski/Work/foxhunt/ml/src/features/regime_adx.rs` (Error 2)
- `/home/jgrusewski/Work/foxhunt/ml/src/features/extraction.rs` (Error 3)
**Verification**:
```bash
cargo build -p ml --lib
# Expected: 0 errors
```
---
### Phase 3: Test Validation (10-15 min)
5. Run full test suite:
```bash
cargo test -p ml --lib
```
6. Run feature extraction tests:
```bash
cargo test -p ml test_feature_extraction_225_dim
```
7. Verify 225-feature dimension:
```bash
cargo test -p ml -- --nocapture | grep "225"
```
---
## Long-Term Solution: Type Unification
**Problem**: 3 different `OHLCVBar` types cause confusion and compilation errors.
**Proposal**: Move to `common/src/features/types.rs`
```rust
// common/src/features/types.rs
use chrono::{DateTime, Utc};
/// Unified OHLCV bar type (Wave B/D)
#[derive(Debug, Clone, Copy)]
pub struct OHLCVBar {
pub timestamp: DateTime<Utc>,
pub open: f64,
pub high: f64,
pub low: f64,
pub close: f64,
pub volume: f64,
}
```
**Migration**:
1. Add to `common/src/features/types.rs`
2. Update `ml/src/features/alternative_bars.rs` to use `common::features::OHLCVBar`
3. Update `ml/src/features/regime_adx.rs` to use `common::features::OHLCVBar`
4. Update `ml/src/features/extraction.rs` to use `common::features::OHLCVBar`
5. Remove duplicate definitions
**Estimated Time**: 1-2 hours (includes testing)
**Risk**: Low (existing tests will catch any issues)
---
## Impact Assessment
### Compilation
- **Errors**: 5 (3 type mismatches, 2 field access)
- **Estimated Fix Time**: 30-60 min (Phase 1 + Phase 2)
- **Blocking**: Yes (cannot proceed to Wave 3 until fixed)
### Testing
- **Current Status**: Cannot run tests until compilation fixed
- **Expected Impact**: Unknown (tests may fail after fix)
- **Mitigation**: Fix errors first, then run tests
### Model Training
- **DQN**: ✅ Already retrained with 225 features (model size +127.6%)
- **MAMBA-2**: ⚠️ Blocked by compilation errors (uses `dbn_sequence_loader.rs`)
- **TFT**: ⚠️ Blocked by compilation errors (uses `dbn_sequence_loader.rs`)
- **PPO**: ⚠️ Unclear (model size unchanged, may need validation)
---
## Success Criteria
### Phase 1 Complete (5 min)
```bash
cargo build -p ml --lib 2>&1 | grep "^error" | wc -l
# Expected: 2 errors remaining (type mismatches)
```
### Phase 2 Complete (30 min)
```bash
cargo build -p ml --lib
# Expected: 0 errors, compilation successful
```
### Phase 3 Complete (15 min)
```bash
cargo test -p ml --lib
# Expected: >95% test pass rate
```
---
## Next Agent Tasks
### Wave2-Fix-01: Fix Compilation Errors (30-60 min)
**Input**: This document
**Output**: All 5 errors fixed, compilation successful
**Tasks**:
1. Fix Error 1 (timestamp)
2. Fix Error 4-5 (DBN field access)
3. Fix Error 2 (ADX type conversion)
4. Fix Error 3 (Adaptive type conversion)
5. Verify compilation
### Wave3-01: PPO Validation (1-2 hours)
**Input**: Compiled ml crate
**Output**: PPO validated with 225 features
**Tasks**:
1. Check PPO trainer dimension configuration
2. Verify actor/critic network input dimensions
3. Run PPO training test
4. Validate model file sizes
5. Document results
---
**Report Generated**: 2025-10-20
**Author**: Wave 2 Agent 14