This commit is contained in:
zhangkun9038@dingtalk.com 2025-04-29 14:05:46 +08:00
parent 4cdd0c9d1e
commit b5f733c2f2

View File

@ -288,11 +288,15 @@ class FreqaiExampleStrategy(IStrategy):
if col in ["buy_rsi_pred", "sell_rsi_pred"]:
dataframe[col] = dataframe[col].clip(lower=10, upper=90) # Keep RSI values within valid range
# Ensure buy_rsi_pred exists before using it
# Final validation of buy_rsi_pred
if "buy_rsi_pred" not in dataframe.columns:
logger.error("buy_rsi_pred column still missing after initialization, aborting")
raise ValueError("Failed to initialize required buy_rsi_pred column")
# Ensure buy_rsi_pred has valid values
dataframe["buy_rsi_pred"] = dataframe["buy_rsi_pred"].clip(lower=10, upper=90)
dataframe["buy_rsi_pred"] = dataframe["buy_rsi_pred"].fillna(30)
# Initialize columns before any calculations
for col, default_value in pred_columns.items():
# Create column if it doesn't exist
@ -319,6 +323,11 @@ class FreqaiExampleStrategy(IStrategy):
logger.error("buy_rsi_pred column still missing after initialization, aborting")
raise ValueError("Failed to initialize required buy_rsi_pred column")
# Ensure buy_rsi_pred exists with proper initialization
if "buy_rsi_pred" not in dataframe.columns:
logger.warning("buy_rsi_pred column missing, initializing with default value 30")
dataframe["buy_rsi_pred"] = 30
# Now perform calculations that depend on these columns
dataframe["sell_rsi_pred"] = dataframe["buy_rsi_pred"] + 20
dataframe["sell_rsi_pred"] = dataframe["sell_rsi_pred"].fillna(dataframe["sell_rsi_pred"].median())