确保 &-buy_rsi 列的值计算正确
Some checks are pending
Update Docker Hub Description / dockerHubDescription (push) Waiting to run
Some checks are pending
Update Docker Hub Description / dockerHubDescription (push) Waiting to run
This commit is contained in:
parent
05b65162a1
commit
86e9a2ab61
@ -121,7 +121,17 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
|
||||
# 单一回归目标
|
||||
# 移除对未来的数据依赖
|
||||
dataframe["&-buy_rsi"] = ta.RSI(dataframe, timeperiod=14)
|
||||
# 确保 &-buy_rsi 列的值计算正确
|
||||
dataframe["&-buy_rsi"] = ta.RSI(dataframe, timeperiod=14)
|
||||
|
||||
# 数据清理
|
||||
for col in ["&-buy_rsi"]:
|
||||
# 使用直接操作避免链式赋值
|
||||
dataframe[col] = dataframe[col].replace([np.inf, -np.inf], np.nan)
|
||||
dataframe[col] = dataframe[col].ffill() # 替代 fillna(method='ffill')
|
||||
dataframe[col] = dataframe[col].fillna(dataframe[col].mean()) # 使用均值填充 NaN 值
|
||||
if dataframe[col].isna().any():
|
||||
logger.warning(f"目标列 {col} 仍包含 NaN,填充为默认值")
|
||||
|
||||
# 数据清理
|
||||
for col in ["&-buy_rsi", "%-volatility"]:
|
||||
@ -230,7 +240,7 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
# 改进卖出信号条件
|
||||
exit_long_conditions = [
|
||||
(df["rsi"] > df["sell_rsi_pred"]) & (df["rsi"].shift(1) <= df["sell_rsi_pred"]), # RSI 上穿卖出阈值
|
||||
(df["rsi"] > df["sell_rsi_pred"]), # RSI 高于卖出阈值
|
||||
df["volume"] > df["volume"].rolling(window=10).mean(), # 成交量高于近期均值
|
||||
df["close"] < df["bb_middleband"] # 价格低于布林带中轨
|
||||
]
|
||||
@ -243,7 +253,7 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
# 改进买入信号条件
|
||||
enter_long_conditions = [
|
||||
(df["rsi"] < df["buy_rsi_pred"]) & (df["rsi"].shift(1) >= df["buy_rsi_pred"]), # RSI 下穿买入阈值
|
||||
(df["rsi"] < df["buy_rsi_pred"]), # RSI 低于买入阈值
|
||||
df["volume"] > df["volume"].rolling(window=10).mean(), # 成交量高于近期均值
|
||||
df["close"] > df["bb_middleband"] # 价格高于布林带中轨
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user