出场置信度
This commit is contained in:
parent
cc75e2a6fc
commit
9c77455e1b
@ -248,6 +248,10 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 入场间隔控制参数(分钟)
|
||||
entry_interval_minutes = IntParameter(20, 200, default=42, optimize=True, load=True, space='buy')
|
||||
|
||||
# ML 审核官:exit_signal 拒绝入场的阈值(越高越宽松,越低越严格)
|
||||
ml_exit_signal_threshold = DecimalParameter(0.50, 0.85, decimals=2, default=0.65, optimize=True, load=True, space='buy')
|
||||
|
||||
# 定义可优化参数
|
||||
# 初始入场金额: 75.00
|
||||
|
||||
@ -740,31 +744,36 @@ class FreqaiPrimer(IStrategy):
|
||||
allow_trade = False
|
||||
|
||||
# 检查3:ML 审核官(FreqAI 过滤低质量入场)
|
||||
# 逻辑:用 exit_signal 概率来判断——若"退出概率高"说明价格容易跌,则拒绝入场
|
||||
if allow_trade:
|
||||
try:
|
||||
df, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
if len(df) > 0:
|
||||
last_row = df.iloc[-1]
|
||||
ml_score = None
|
||||
# 优先使用 FreqAI 预测列(例如 &-entry_signal_prob 或 &-entry_signal)
|
||||
if '&-entry_signal_prob' in df.columns:
|
||||
ml_score = float(last_row['&-entry_signal_prob'])
|
||||
elif '&-entry_signal' in df.columns:
|
||||
val = last_row['&-entry_signal']
|
||||
exit_prob = None
|
||||
|
||||
# 优先使用 FreqAI 的 exit_signal 预测列(例如 &-exit_signal_prob 或 &-exit_signal)
|
||||
if '&-exit_signal_prob' in df.columns:
|
||||
exit_prob = float(last_row['&-exit_signal_prob'])
|
||||
elif '&-s-exit_signal_prob' in df.columns:
|
||||
exit_prob = float(last_row['&-s-exit_signal_prob'])
|
||||
elif '&-exit_signal' in df.columns:
|
||||
val = last_row['&-exit_signal']
|
||||
if isinstance(val, (int, float)):
|
||||
ml_score = float(val)
|
||||
exit_prob = float(val)
|
||||
else:
|
||||
# 文本标签时,简单映射为 0/1
|
||||
ml_score = 1.0 if str(val).lower() in ['good', 'enter', 'long', '1'] else 0.0
|
||||
elif 'prediction' in df.columns:
|
||||
# 回归模型时,可直接用 prediction 作为质量分(需在FreqAI侧归一化到0-1)
|
||||
ml_score = float(last_row['prediction'])
|
||||
exit_prob = 1.0 if str(val).lower() in ['exit', 'sell', '1'] else 0.0
|
||||
|
||||
if ml_score is not None:
|
||||
ml_threshold = 0.6
|
||||
if ml_score < ml_threshold:
|
||||
logger.info(f"[{pair}] ML 审核官拒绝入场: 质量分 {ml_score:.2f} < 阈值 {ml_threshold:.2f}")
|
||||
if exit_prob is not None:
|
||||
# 阈值:如果"应该退出"的概率 > 阈值,说明价格很可能下跌,拒绝入场
|
||||
# 使用 hyperopt 参数,默认 0.65(比之前的 0.5 更宽松)
|
||||
exit_threshold = self.ml_exit_signal_threshold.value
|
||||
if exit_prob > exit_threshold:
|
||||
logger.info(f"[{pair}] ML 审核官拒绝入场: exit_signal 概率 {exit_prob:.2f} > 阈值 {exit_threshold:.2f}(容易下跌,不宜入场)")
|
||||
allow_trade = False
|
||||
# else:
|
||||
# logger.info(f"[{pair}] ML 审核官允许入场: exit_signal 概率 {exit_prob:.2f} <= {exit_threshold:.2f}")
|
||||
except Exception as e:
|
||||
logger.warning(f"[{pair}] ML 审核官检查失败,忽略 ML 过滤: {e}")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user