Hierarchical ML Pipeline for trading predictions:
- Level 0: Attention Models (volatility/flow classification)
- Level 1: Base Models (XGBoost per symbol/timeframe)
- Level 2: Metamodels (XGBoost Stacking + Neural Gating)
Key components:
- src/pipelines/hierarchical_pipeline.py - Main prediction pipeline
- src/models/ - All ML model classes
- src/training/ - Training utilities
- src/api/ - FastAPI endpoints
- scripts/ - Training and evaluation scripts
- config/ - YAML configurations
Note: Trained models (*.joblib, *.pt) are gitignored.
Regenerate with training scripts.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
167 lines
4.8 KiB
Markdown
167 lines
4.8 KiB
Markdown
# Attention Score Model Training Report
|
|
|
|
**Generated:** 2026-01-06 23:57:59
|
|
|
|
## Overview
|
|
|
|
The attention model learns to identify high-flow market moments using volume, volatility, and money flow indicators - WITHOUT hardcoding specific trading hours or sessions.
|
|
|
|
## Configuration
|
|
|
|
- **Symbols:** XAUUSD, EURUSD
|
|
- **Timeframes:** 5m, 15m
|
|
- **Training Data Cutoff:** 2024-03-01
|
|
- **Training Years:** 5.0
|
|
- **Holdout Years:** 1.0
|
|
|
|
### Model Parameters
|
|
|
|
| Parameter | Value |
|
|
|-----------|-------|
|
|
| Factor Window | 200 |
|
|
| Horizon Bars | 3 |
|
|
| Low Flow Threshold | 1.0 |
|
|
| High Flow Threshold | 2.0 |
|
|
|
|
### Features Used (9 total)
|
|
|
|
| Feature | Description |
|
|
|---------|-------------|
|
|
| volume_ratio | volume / rolling_median(volume, 20) |
|
|
| volume_z | z-score of volume over 20 periods |
|
|
| ATR | Average True Range (14 periods) |
|
|
| ATR_ratio | ATR / rolling_median(ATR, 50) |
|
|
| CMF | Chaikin Money Flow (20 periods) |
|
|
| MFI | Money Flow Index (14 periods) |
|
|
| OBV_delta | diff(OBV) / rolling_std(OBV, 20) |
|
|
| BB_width | (BB_upper - BB_lower) / close |
|
|
| displacement | (close - open) / ATR |
|
|
|
|
## Training Results
|
|
|
|
| Model | Symbol | TF | Reg MAE | Reg R2 | Clf Acc | Clf F1 | N Train | High Flow % |
|
|
|-------|--------|-----|---------|--------|---------|--------|---------|-------------|
|
|
| XAUUSD_5m_attention | XAUUSD | 5m | 0.8528 | 0.1914 | 61.44% | 57.96% | 288386 | 23.1% |
|
|
| XAUUSD_15m_attention | XAUUSD | 15m | 0.8564 | 0.1250 | 59.39% | 54.70% | 96801 | 25.8% |
|
|
| EURUSD_5m_attention | EURUSD | 5m | 0.6678 | 0.1569 | 54.07% | 49.84% | 312891 | 34.3% |
|
|
| EURUSD_15m_attention | EURUSD | 15m | 0.6405 | 0.2193 | 60.70% | 57.20% | 104659 | 36.3% |
|
|
|
|
|
|
## Class Distribution (Holdout Set)
|
|
|
|
| Model | Low Flow | Medium Flow | High Flow |
|
|
|-------|----------|-------------|-----------|
|
|
| XAUUSD_5m_attention | 265 (0.4%) | 53705 (76.5%) | 16238 (23.1%) |
|
|
| XAUUSD_15m_attention | 0 (0.0%) | 17566 (74.2%) | 6106 (25.8%) |
|
|
| EURUSD_5m_attention | 2380 (3.2%) | 46893 (62.5%) | 25781 (34.3%) |
|
|
| EURUSD_15m_attention | 443 (1.8%) | 15629 (62.0%) | 9143 (36.3%) |
|
|
|
|
|
|
## Feature Importance
|
|
|
|
### XAUUSD_5m_attention
|
|
|
|
| Rank | Feature | Combined Importance |
|
|
|------|---------|--------------------|
|
|
| 1 | ATR_ratio | 0.4240 |
|
|
| 2 | BB_width | 0.1601 |
|
|
| 3 | ATR | 0.1229 |
|
|
| 4 | CMF | 0.1164 |
|
|
| 5 | volume_ratio | 0.0639 |
|
|
| 6 | volume_z | 0.0399 |
|
|
| 7 | displacement | 0.0331 |
|
|
| 8 | OBV_delta | 0.0213 |
|
|
| 9 | MFI | 0.0184 |
|
|
|
|
### XAUUSD_15m_attention
|
|
|
|
| Rank | Feature | Combined Importance |
|
|
|------|---------|--------------------|
|
|
| 1 | ATR_ratio | 0.3364 |
|
|
| 2 | volume_ratio | 0.1779 |
|
|
| 3 | BB_width | 0.1414 |
|
|
| 4 | volume_z | 0.1034 |
|
|
| 5 | displacement | 0.0743 |
|
|
| 6 | ATR | 0.0651 |
|
|
| 7 | OBV_delta | 0.0441 |
|
|
| 8 | CMF | 0.0331 |
|
|
| 9 | MFI | 0.0243 |
|
|
|
|
### EURUSD_5m_attention
|
|
|
|
| Rank | Feature | Combined Importance |
|
|
|------|---------|--------------------|
|
|
| 1 | ATR_ratio | 0.3577 |
|
|
| 2 | BB_width | 0.2217 |
|
|
| 3 | ATR | 0.1566 |
|
|
| 4 | volume_ratio | 0.0765 |
|
|
| 5 | CMF | 0.0569 |
|
|
| 6 | volume_z | 0.0536 |
|
|
| 7 | displacement | 0.0315 |
|
|
| 8 | OBV_delta | 0.0264 |
|
|
| 9 | MFI | 0.0191 |
|
|
|
|
### EURUSD_15m_attention
|
|
|
|
| Rank | Feature | Combined Importance |
|
|
|------|---------|--------------------|
|
|
| 1 | ATR_ratio | 0.5007 |
|
|
| 2 | volume_ratio | 0.1497 |
|
|
| 3 | volume_z | 0.1129 |
|
|
| 4 | ATR | 0.0990 |
|
|
| 5 | BB_width | 0.0396 |
|
|
| 6 | displacement | 0.0284 |
|
|
| 7 | CMF | 0.0254 |
|
|
| 8 | OBV_delta | 0.0245 |
|
|
| 9 | MFI | 0.0198 |
|
|
|
|
|
|
|
|
## Interpretation
|
|
|
|
### Attention Score (Regression)
|
|
|
|
- **< 1.0**: Low flow period - below average market movement expected
|
|
- **1.0 - 2.0**: Medium flow period - average market conditions
|
|
- **> 2.0**: High flow period - above average movement expected (best trading opportunities)
|
|
|
|
### Flow Class (Classification)
|
|
|
|
- **0 (low_flow)**: move_multiplier < 1.0
|
|
- **1 (medium_flow)**: 1.0 <= move_multiplier < 2.0
|
|
- **2 (high_flow)**: move_multiplier >= 2.0
|
|
|
|
## Trading Recommendations
|
|
|
|
1. **Filter by attention_score**: Only trade when attention_score > 1.0
|
|
2. **Adjust position sizing**: Increase size when attention_score > 2.0
|
|
3. **Combine with base models**: Use attention_score as feature #51 in prediction models
|
|
4. **Time-agnostic**: The model identifies flow without hardcoded sessions
|
|
|
|
## Usage Example
|
|
|
|
```python
|
|
from training.attention_trainer import AttentionModelTrainer
|
|
|
|
# Load trained models
|
|
trainer = AttentionModelTrainer.load('models/attention/')
|
|
|
|
# Get attention score for new OHLCV data
|
|
attention = trainer.get_attention_score(df_ohlcv, 'XAUUSD', '5m')
|
|
|
|
# Filter trades
|
|
mask_trade = attention > 1.0 # Only trade in medium/high flow
|
|
|
|
# Or use as feature in base models
|
|
df['attention_score'] = attention
|
|
```
|
|
|
|
## Files Generated
|
|
|
|
- `models/attention/{symbol}_{timeframe}_attention/` - Model directories
|
|
- `models/attention/trainer_metadata.joblib` - Trainer configuration
|
|
- `models/attention/training_summary.csv` - Summary metrics
|
|
|
|
---
|
|
*Report generated by Attention Model Training Pipeline*
|