From 9bfb7b86d78636a36eabdeedc421a63c8182ead2 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Thu, 18 Dec 2025 14:00:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=86=8A=E5=B8=82=20Crash=20=E6=8A=84=E5=BA=95?= =?UTF-8?q?+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- freqtrade/templates/freqaiprimer.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/freqtrade/templates/freqaiprimer.py b/freqtrade/templates/freqaiprimer.py index 1502f2df..dde92ba4 100644 --- a/freqtrade/templates/freqaiprimer.py +++ b/freqtrade/templates/freqaiprimer.py @@ -394,11 +394,14 @@ class FreqaiPrimer(IStrategy): # ========== 入场置信度标签 ========== # 基于未来收益率估算入场好坏,使用 S 型函数映射到 0-1 future_return = dataframe["close"].shift(-label_period) / dataframe["close"] - 1 - dataframe["&-entry_confidence"] = 1 / (1 + np.exp(-future_return * 50)) + # 先填充 NaN 再计算 sigmoid,避免 NaN 传播 + future_return_filled = future_return.ffill().fillna(0) + dataframe["&-entry_confidence"] = 1 / (1 + np.exp(-future_return_filled * 50)) - # ========== 统一处理 NaN,避免训练数据被全部过滤 ========== + # ========== 二次保险:确保最终标签没有 NaN ========== if "&-entry_confidence" in dataframe.columns: - dataframe["&-entry_confidence"] = dataframe["&-entry_confidence"].fillna(method='ffill').fillna(0) + # 使用 0.5(中性置信度)填充任何剩余的 NaN + dataframe["&-entry_confidence"] = dataframe["&-entry_confidence"].fillna(0.5) return dataframe