Files
XauBot/backtests/ml_v3/convert_model_format.py
GifariKemal 0f9548e5fb feat: implement Professor AI recommendations v0.2.2 (5 critical fixes)
Exit Strategy v6.6 "Professor AI Validated" - All recommendations implemented

FIX #1: Remove Misleading Debug Code
- Removed manual trajectory calculation (line 1262-1269)
- Trajectory predictor was CORRECT, debug comparison was WRONG
- Cleaned up false "bug found" warnings

FIX #2: Peak Detection Logic (CHECK 0A.4)
- Detects approaching peak (vel > 0, accel < 0)
- Holds position if peak within 30s and 15%+ profit ahead
- Suppresses fuzzy exits during peak approach
- Target: Peak capture 38% -> 70%+
- Added peak_hold_active field to PositionGuard

FIX #3: London False Breakout Filter
- London session + ATR ratio < 1.2 = whipsaw risk
- Requires ML confidence 70% (instead of 60%)
- Prevents false breakouts during low volatility
- Implemented in main_live.py before signal logic

FIX #4: Enhanced Kelly Partial Exit Strategy
- Active for all profits >= tp_min * 0.5 (not just >$8)
- Recommends partial exits for better peak capture
- Full exit when Kelly suggests >70% close
- Note: Actual partial close needs MT5 volume parameter (TODO)

FIX #5: Unicode Encoding Fixes
- Added UTF-8 encoding to file logger
- Replaced all emoji (⚠️ -> [WARNING]) and arrows (-> -> ->)
- No more UnicodeEncodeError on Windows console
- Fixed in 11 src/*.py files

Expected Performance:
- Peak Capture: 38% -> 70%+ (+84%)
- Avg Profit: $2.00 -> $4.50 (+125%)
- Risk/Reward: 0.49 -> 1.2+ (+145%)
- Win Rate: Maintain 76%

Files Modified:
- src/smart_risk_manager.py (peak detection, Kelly, unicode)
- src/trajectory_predictor.py (unicode arrows)
- main_live.py (London filter, UTF-8 encoding)
- src/*.py (unicode cleanup: 11 files)
- VERSION (0.2.1 -> 0.2.2)
- CHANGELOG.md (comprehensive v0.2.2 docs)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-11 18:16:34 +07:00

53 lines
1.6 KiB
Python

"""
Convert ML V3 model to TradingModelV2 compatible format.
"""
import pickle
import sys
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from backtests.ml_v2.ml_v2_model import ModelType
# Load old format
old_path = Path("backtests/ml_v3/xgboost_model_v3.pkl")
with open(old_path, 'rb') as f:
old_data = pickle.load(f)
print(f"Loaded model from: {old_path}")
print(f"Old keys: {list(old_data.keys())}")
# Convert to TradingModelV2 format
new_data = {
'xgb_model': old_data['model'], # XGBoost Booster object
'lgb_model': None,
'model_type': ModelType.XGBOOST_BINARY,
'feature_names': old_data['feature_cols'],
'confidence_threshold': 0.60,
'xgb_params': old_data['metadata'].get('hyperparameters', {}),
'lgb_params': {},
'feature_importance': {},
'train_metrics': {
'train_accuracy': old_data['metadata']['train_accuracy'],
'test_accuracy': old_data['metadata']['test_accuracy'],
},
'fitted': True,
'metadata': old_data['metadata'],
'version': '3.0_binary',
'trained_at': old_data['trained_at'],
'symbol': old_data['symbol'],
'timeframe': old_data['timeframe']
}
# Save new format
with open(old_path, 'wb') as f:
pickle.dump(new_data, f)
print(f"\n✅ Model converted to TradingModelV2 format!")
print(f" Model type: {new_data['model_type'].value}")
print(f" Features: {len(new_data['feature_names'])}")
print(f" Train accuracy: {new_data['train_metrics']['train_accuracy']:.4f}")
print(f" Test accuracy: {new_data['train_metrics']['test_accuracy']:.4f}")