feat: 远程MT5数据源 + 信号对冲/回撤锁仓模块

新增:
- core/risk/hedge.py: 对冲管理器
  - 信号对冲: 加权信号反向超阈值→半仓反向
  - 回撤锁仓: 浮亏超-0.3%→全仓锁死
  - 自动解锁: 信号回正/对冲止盈0.5%

改动:
- run/backtest.py: 支持远程数据源回测
- run/realtime.py: 远程/本地双模式
- core/risk/position.py: 集成HedgeManager
- core/risk/controller.py: 传递weighted_signal
- execution/realtime_trader.py: 传入加权信号
- core/data/live.py, utils.py: MetaTrader5懒加载(ARM兼容)
- config.py: HEDGE_CONFIG, REMOTE配置, INITIAL_CAPITAL=1944

今日实盘: 9单, +7.4% (944→088)
This commit is contained in:
songkl
2026-05-11 23:46:49 +08:00
parent 4cb4f4a15e
commit 878e0f4a03
10 changed files with 478 additions and 89 deletions
+15 -1
View File
@@ -8,6 +8,7 @@ from config import (
RISK_CONFIG_CONST, SIMULATION_CONFIG
)
from core.risk.exit_rules import ExitRuleEngine, ExitContext
from core.risk.hedge import HedgeManager
class PositionManager:
@@ -70,6 +71,10 @@ class PositionManager:
if self._persist_peaks:
self._load_peak_data()
# 对冲管理器
from config import HEDGE_CONFIG
self.hedge_manager = HedgeManager(self, HEDGE_CONFIG)
# ── 仓位计算 ──
def _calculate_position_size(self, capital_to_allocate, current_price):
@@ -180,7 +185,7 @@ class PositionManager:
# ── 持仓监控 ──
def monitor_positions(self, current_price, dry_run=False):
def monitor_positions(self, current_price, dry_run=False, weighted_signal=0.0):
if not self.positions:
return
@@ -231,6 +236,15 @@ class PositionManager:
self.update_equity()
self.cleanup_peak_data()
# ── 对冲评估 ──
if self.positions and self.hedge_manager:
hedge_actions = self.hedge_manager.evaluate(weighted_signal, current_price)
for action, target, reason in hedge_actions:
if action == "hedge":
self.hedge_manager.execute_hedge(target, reason, current_price)
elif action == "unhedge":
self.hedge_manager.execute_unhedge(target, reason)
# ── 盈亏计算 ──
def _calculate_pnl_pct(self, position, current_price_value):