Changes include: - Updated architecture documentation - Enhanced module definitions (OQI-001 to OQI-008) - ML integration documentation updates - Trading strategies documentation - Orchestration and inventory updates - Docker configuration updates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
298 lines
17 KiB
Markdown
298 lines
17 KiB
Markdown
---
|
|
title: "Análisis de Modelos ML - Vuelta 3 (FINAL)"
|
|
version: "1.0.0"
|
|
date: "2026-01-06"
|
|
status: "Final"
|
|
author: "ML-Specialist + Orquestador"
|
|
epic: "OQI-006"
|
|
tags: ["ml", "final", "solution", "implementation"]
|
|
---
|
|
|
|
# ANÁLISIS DE MODELOS ML - VUELTA 3 (DOCUMENTO FINAL)
|
|
|
|
## 1. RESUMEN EJECUTIVO
|
|
|
|
### 1.1 Objetivo del Análisis
|
|
Redefinir la documentación y arquitectura de los modelos ML de trading-platform para:
|
|
- Alcanzar 80%+ win rate en movimientos fuertes
|
|
- Implementar sistema de atención con factores dinámicos (no hardcoded)
|
|
- Escalar de 3 a 100+ activos
|
|
- Gestión de riesgo 2:1 o 3:1 (TP:SL)
|
|
|
|
### 1.2 Hallazgo Principal
|
|
> **La infraestructura necesaria YA EXISTE, pero NO está integrada**
|
|
|
|
| Componente | Estado | Ubicación |
|
|
|------------|--------|-----------|
|
|
| Modelos por símbolo/timeframe | ✅ Existe | `models/ml_first/{symbol}/{tf}/` |
|
|
| Trainer separado | ✅ Existe | `symbol_timeframe_trainer.py` |
|
|
| Factores dinámicos | ✅ Existe | `SYMBOL_CONFIGS` |
|
|
| Attention weighting | ✅ Existe | `DynamicFactorWeighter` |
|
|
| Transformer con volatility bias | ✅ Existe | `VolatilityRangePredictor` |
|
|
| **Integración en producción** | ❌ Falta | `prediction_service.py` usa legacy |
|
|
|
|
### 1.3 Métricas Actuales vs Objetivo
|
|
|
|
| Métrica | Actual | Objetivo Inmediato | Meta Final |
|
|
|---------|--------|-------------------|------------|
|
|
| Win Rate | 33-44% | 55-60% | 80%+ |
|
|
| Profit Factor | 1.07 | 1.3 | 1.8+ |
|
|
| R:R Ratio | 1.2:1 | 1.8:1 | 2.5:1 |
|
|
| Max Drawdown | 15% | 12% | 10% |
|
|
| Símbolos soportados | 2-3 | 5+ | 100+ |
|
|
|
|
---
|
|
|
|
## 2. ARQUITECTURA DE SOLUCIÓN
|
|
|
|
### 2.1 Diagrama de Arquitectura Propuesta
|
|
|
|
```
|
|
┌─────────────────────────────────────────────────────────────────────────┐
|
|
│ ML PREDICTION SYSTEM v2.0 │
|
|
├─────────────────────────────────────────────────────────────────────────┤
|
|
│ │
|
|
│ ┌───────────────┐ ┌────────────────┐ ┌──────────────────────┐ │
|
|
│ │ API Layer │ │ Prediction │ │ Model Registry │ │
|
|
│ │ (FastAPI) │───▶│ Service v2 │───▶│ │ │
|
|
│ │ │ │ │ │ models/ml_first/ │ │
|
|
│ │ /predict/ │ │ Symbol-aware │ │ ├── XAUUSD/ │ │
|
|
│ │ /signals/ │ │ loading │ │ │ ├── 5m/ │ │
|
|
│ │ /amd/ │ │ │ │ │ └── 15m/ │ │
|
|
│ │ /ensemble/ │ └────────┬───────┘ │ ├── EURUSD/ │ │
|
|
│ └───────────────┘ │ │ └── BTCUSD/ │ │
|
|
│ │ └──────────────────────┘ │
|
|
│ ▼ │
|
|
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
│ │ ATTENTION LAYER │ │
|
|
│ ├─────────────────────────────────────────────────────────────────┤ │
|
|
│ │ ┌──────────────────┐ ┌───────────────────┐ ┌──────────────┐ │ │
|
|
│ │ │ DynamicFactor │ │ Softplus Mapping │ │ Sample │ │ │
|
|
│ │ │ Calculator │ │ │ │ Weighting │ │ │
|
|
│ │ │ │ │ m = delta/factor │ │ │ │ │
|
|
│ │ │ factor = median( │ │ w = softplus(m-1) │ │ XGBoost: │ │ │
|
|
│ │ │ range, │ │ w = clip(w, 0, 3) │ │ sample_weight│ │ │
|
|
│ │ │ window=200 │ │ │ │ │ │ │
|
|
│ │ │ ).shift(1) │ │ m<1 → w≈0 (noise) │ │ Transformer: │ │ │
|
|
│ │ │ │ │ m=2 → w≈1 (signal)│ │ attn_bias │ │ │
|
|
│ │ └──────────────────┘ └───────────────────┘ └──────────────┘ │ │
|
|
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
│ │
|
|
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
│ │ MODEL ENSEMBLE │ │
|
|
│ ├─────────────────────────────────────────────────────────────────┤ │
|
|
│ │ │ │
|
|
│ │ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ │
|
|
│ │ │ XGBoost │ │ AMD │ │ ICT/SMC │ │ TP/SL │ │ │
|
|
│ │ │ Range │ │ Detector │ │ Detector │ │ Classifier │ │ │
|
|
│ │ │ Predictor │ │ │ │ │ │ │ │ │
|
|
│ │ │ │ │ Phase: │ │ Order │ │ P(TP first)│ │ │
|
|
│ │ │ ΔHigh/ΔLow │ │ A/M/D │ │ Blocks, │ │ 2:1, 3:1 │ │ │
|
|
│ │ │ │ │ │ │ FVG │ │ │ │ │
|
|
│ │ │ Weight:35% │ │ Weight:20% │ │ Weight:25% │ │ Weight:20% │ │ │
|
|
│ │ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │ │
|
|
│ │ │ │ │
|
|
│ │ ▼ │ │
|
|
│ │ ┌────────────────────────────────────────────────────────────┐ │ │
|
|
│ │ │ META-MODEL (XGBoost) │ │ │
|
|
│ │ │ Features: [pred_high, pred_low, amd_phase, ict_score, │ │ │
|
|
│ │ │ prob_tp, volatility, session, attention_weight] │ │ │
|
|
│ │ └────────────────────────────────────────────────────────────┘ │ │
|
|
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
│ │
|
|
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
│ │ DIRECTIONAL FILTERS │ │
|
|
│ ├─────────────────────────────────────────────────────────────────┤ │
|
|
│ │ SHORT (2+ confirmaciones): LONG (3+ confirmaciones): │ │
|
|
│ │ ├── RSI > 55 ├── RSI < 35 │ │
|
|
│ │ ├── SAR above price ├── SAR below price │ │
|
|
│ │ ├── CMF < 0 ├── CMF > 0.1 │ │
|
|
│ │ └── MFI > 55 └── MFI < 35 │ │
|
|
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
│ │
|
|
│ OUTPUT: { direction, entry, sl, tp, confidence, attention_weight } │
|
|
└─────────────────────────────────────────────────────────────────────────┘
|
|
```
|
|
|
|
### 2.2 Configuración Centralizada
|
|
|
|
**Archivo propuesto**: `config/symbols.yaml`
|
|
|
|
```yaml
|
|
symbols:
|
|
XAUUSD:
|
|
base_factor: 5.0 # USD - rango típico 5m
|
|
pip_value: 0.01
|
|
typical_spread: 0.30
|
|
direction_bias: short # Basado en backtests
|
|
min_confidence: 0.70
|
|
|
|
BTCUSD:
|
|
base_factor: 100.0 # USD - rango típico 5m
|
|
pip_value: 0.01
|
|
typical_spread: 10.0
|
|
direction_bias: none
|
|
min_confidence: 0.75
|
|
|
|
EURUSD:
|
|
base_factor: 0.0005 # ~5 pips
|
|
pip_value: 0.0001
|
|
typical_spread: 0.0001
|
|
direction_bias: none
|
|
min_confidence: 0.70
|
|
|
|
GBPUSD:
|
|
base_factor: 0.0006 # ~6 pips
|
|
pip_value: 0.0001
|
|
typical_spread: 0.00012
|
|
direction_bias: none
|
|
min_confidence: 0.70
|
|
|
|
USDJPY:
|
|
base_factor: 0.05 # ~5 pips
|
|
pip_value: 0.01
|
|
typical_spread: 0.012
|
|
direction_bias: none
|
|
min_confidence: 0.70
|
|
|
|
defaults:
|
|
factor_window: 200
|
|
softplus_beta: 4.0
|
|
softplus_w_max: 3.0
|
|
min_attention: 1.5 # Solo señales con attention >= 1.5
|
|
```
|
|
|
|
---
|
|
|
|
## 3. PLAN DE IMPLEMENTACIÓN
|
|
|
|
### 3.1 Fases de Implementación
|
|
|
|
```
|
|
╔═══════════════════════════════════════════════════════════════════════╗
|
|
║ ROADMAP DE IMPLEMENTACIÓN ║
|
|
╠═══════════════════════════════════════════════════════════════════════╣
|
|
║ ║
|
|
║ FASE 1: Quick Wins (Semana 1) ║
|
|
║ ├── [1] Activar filtros direccionales en signal_generator.py ║
|
|
║ ├── [2] Cargar modelos separados en prediction_service.py ║
|
|
║ └── [3] Eliminar factores hardcodeados ║
|
|
║ ║
|
|
║ FASE 2: Integración Attention (Semana 2) ║
|
|
║ ├── [4] Integrar DynamicFactorWeighter en pipeline ║
|
|
║ ├── [5] Agregar attention_weight a output de API ║
|
|
║ └── [6] Filtrar señales por min_attention >= 1.5 ║
|
|
║ ║
|
|
║ FASE 3: Metamodelo (Semana 3-4) ║
|
|
║ ├── [7] Implementar MetamodelEnsemble con pesos adaptativos ║
|
|
║ ├── [8] Reentrenar modelos con attention weighting ║
|
|
║ └── [9] Backtesting extensivo (3 meses) ║
|
|
║ ║
|
|
║ FASE 4: Escalamiento (Semana 5+) ║
|
|
║ ├── [10] Agregar 5 símbolos adicionales ║
|
|
║ ├── [11] Automatizar reentrenamiento semanal ║
|
|
║ └── [12] Dashboard de monitoreo ║
|
|
║ ║
|
|
╚═══════════════════════════════════════════════════════════════════════╝
|
|
```
|
|
|
|
### 3.2 Estimación de Impacto por Fase
|
|
|
|
| Fase | Win Rate Esperado | Effort | Riesgo |
|
|
|------|-------------------|--------|--------|
|
|
| FASE 1 | 44% → 55% | 1 semana | Bajo |
|
|
| FASE 2 | 55% → 65% | 1 semana | Bajo |
|
|
| FASE 3 | 65% → 75% | 2 semanas | Medio |
|
|
| FASE 4 | 75% → 80% | 2+ semanas | Medio |
|
|
|
|
---
|
|
|
|
## 4. ENTREGABLES GENERADOS
|
|
|
|
### 4.1 Documentos de Análisis
|
|
|
|
| Documento | Descripción | Ubicación |
|
|
|-----------|-------------|-----------|
|
|
| ML-MODELOS-VUELTA1-ANALISIS.md | Análisis inicial, inventario de modelos | `docs/99-analisis/` |
|
|
| ML-MODELOS-VUELTA2-ANALISIS.md | Análisis profundo, quick wins | `docs/99-analisis/` |
|
|
| ML-MODELOS-VUELTA3-FINAL.md | Documento final consolidado | `docs/99-analisis/` |
|
|
| ET-ML-FACTORES-ATENCION-SPEC.md | Especificación técnica de factores | `docs/99-analisis/` |
|
|
| ET-REFACTORING-MINIMO-VIABLE.md | Plan de refactoring con código | `docs/99-analisis/` |
|
|
|
|
### 4.2 Archivos de Código Identificados para Modificación
|
|
|
|
| Archivo | Cambio Requerido | Prioridad |
|
|
|---------|------------------|-----------|
|
|
| `prediction_service.py:157` | Cargar modelos separados | ALTA |
|
|
| `range_predictor_factor.py:598-601` | Eliminar SYMBOLS hardcoded | ALTA |
|
|
| `signal_generator.py` | Agregar DirectionalFilters | ALTA |
|
|
| `enhanced_range_predictor.py` | Integrar DynamicFactorWeighter | MEDIA |
|
|
| `strategy_ensemble.py:151-174` | Pesos adaptativos | MEDIA |
|
|
|
|
### 4.3 Configuraciones Propuestas
|
|
|
|
| Archivo | Contenido | Estado |
|
|
|---------|-----------|--------|
|
|
| `config/symbols.yaml` | Configuración centralizada de símbolos | Propuesto |
|
|
| `config/attention.yaml` | Configuración de attention weighting | Propuesto |
|
|
| `config/unified_model.yaml` | Hyperparámetros unificados | Propuesto |
|
|
|
|
---
|
|
|
|
## 5. VALIDACIÓN FINAL
|
|
|
|
### 5.1 Checklist de Validación
|
|
|
|
- [x] Identificados factores hardcodeados y solución
|
|
- [x] Encontrado `SymbolTimeframeTrainer` con factores dinámicos
|
|
- [x] Encontrado `DynamicFactorWeighter` con softplus
|
|
- [x] Encontrado `VolatilityRangePredictor` (Transformer)
|
|
- [x] Encontrado modelos entrenados en `models/ml_first/`
|
|
- [x] Identificado punto de desconexión (`prediction_service.py:157`)
|
|
- [x] Documentados filtros direccionales exitosos (SHORT bias)
|
|
- [x] Propuesto plan de refactoring mínimo viable
|
|
- [x] Definidos tests de regresión
|
|
- [x] Estimado impacto por fase
|
|
|
|
### 5.2 Riesgos y Mitigaciones
|
|
|
|
| Riesgo | Probabilidad | Impacto | Mitigación |
|
|
|--------|--------------|---------|------------|
|
|
| Regresión en win rate | Baja | Alto | Tests de regresión, rollback rápido |
|
|
| Latencia incrementada | Media | Medio | Profiling, lazy loading |
|
|
| Modelos no compatibles | Baja | Alto | Fallback a legacy |
|
|
| Overfitting por atención | Media | Medio | Validación walk-forward |
|
|
|
|
---
|
|
|
|
## 6. CONCLUSIÓN
|
|
|
|
### 6.1 Hallazgo Principal
|
|
El proyecto trading-platform tiene una base sólida de ML con infraestructura avanzada que **no está siendo utilizada en producción**. La brecha principal es de **integración**, no de capacidad.
|
|
|
|
### 6.2 Recomendación
|
|
Implementar el **Refactoring Mínimo Viable** (FASE 1) en la primera semana para obtener mejoras inmediatas del 10-15% en win rate con riesgo bajo.
|
|
|
|
### 6.3 Próximos Pasos Inmediatos
|
|
1. Revisar y aprobar `ET-REFACTORING-MINIMO-VIABLE.md`
|
|
2. Crear branch `feature/ml-integration-v2`
|
|
3. Implementar CAMBIO 3 (filtros direccionales) primero
|
|
4. Ejecutar backtesting para validar
|
|
5. Proceder con CAMBIO 1 y 2
|
|
|
|
---
|
|
|
|
## ANEXO: RESUMEN DE 3 VUELTAS
|
|
|
|
| Vuelta | Foco | Hallazgo Principal |
|
|
|--------|------|-------------------|
|
|
| 1 | Inventario | 15+ modelos ML, factores hardcodeados identificados |
|
|
| 2 | Arquitectura | Infraestructura existe pero no integrada |
|
|
| 3 | Solución | Plan de refactoring con quick wins definidos |
|
|
|
|
---
|
|
|
|
*Documento generado: 2026-01-06*
|
|
*Estado: FINAL - Listo para implementación*
|
|
*Autor: ML-Specialist + Orquestador*
|