加入统计用于回测验证逻辑

This commit is contained in:
zhangkun9038@dingtalk.com 2026-01-07 15:01:58 +08:00
parent 790228fe61
commit 34b9c29dda

View File

@ -779,7 +779,7 @@ class FreqaiPrimer(IStrategy):
#self.strategy_log(f"[{pair}] 由于检测到剧烈拉升,取消入场交易")
allow_trade = False
# 检查3ML 审核官FreqAI 过滤低质量入场)
# 检查3ML 审核官FreqAI 过滤低质量入场)+ 入场诊断统计
# 逻辑:用 entry_signal 概率来判断——若"容易上涨概率"低,则拒绝入场
if allow_trade:
try:
@ -803,6 +803,48 @@ class FreqaiPrimer(IStrategy):
# 文本标签时,简单映射为 0/1
entry_prob = 1.0 if str(val).lower() in ['entry', 'buy', '1'] else 0.0
# ========== 新增:入场诊断统计 ==========
# 统计当前入场点的关键指标,用于分析"买在高位"问题
current_close = float(last_row['close'])
# 1. 价格与短期高点的关系
recent_high_5 = float(df['high'].iloc[-5:].max()) if len(df) >= 5 else current_close
price_vs_recent_high = (current_close - recent_high_5) / recent_high_5 if recent_high_5 > 0 else 0
# 2. 价格与 EMA5 的关系
ema5_1h = float(last_row.get('ema_5_1h', current_close))
price_vs_ema5 = (current_close - ema5_1h) / ema5_1h if ema5_1h > 0 else 0
# 3. 价格与布林带的位置
bb_upper = float(last_row.get('bb_upper_1h', current_close))
bb_lower = float(last_row.get('bb_lower_1h', current_close))
bb_position = (current_close - bb_lower) / (bb_upper - bb_lower) if (bb_upper - bb_lower) > 0 else 0.5
# 4. RSI 状态
rsi_1h = float(last_row.get('rsi_1h', 50))
# 5. MACD 状态
macd_1h = float(last_row.get('macd_1h', 0))
macd_signal_1h = float(last_row.get('macd_signal_1h', 0))
macd_cross = 'up' if macd_1h > macd_signal_1h else 'down'
# 6. 市场状态
market_state = str(last_row.get('market_state', 'unknown'))
# 输出诊断日志
self.strategy_log(
f"[入场诊断] {pair} | "
f"价格: {current_close:.6f} | "
f"vs 5K高点: {price_vs_recent_high:+.2%} | "
f"vs EMA5: {price_vs_ema5:+.2%} | "
f"布林位置: {bb_position:.2f} | "
f"RSI: {rsi_1h:.1f} | "
f"MACD: {macd_cross} | "
f"市场: {market_state} | "
f"ML入场概率: {entry_prob:.2f if entry_prob is not None else 'N/A'}"
)
# ========== 诊断统计结束 ==========
if entry_prob is not None:
# 确保概率在 [0, 1] 范围内(分类器输出可能有浮点误差)
entry_prob = max(0.0, min(1.0, entry_prob))