跟特征数量没关系
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
65116ab7b4
commit
2f4a06d505
@ -74,11 +74,11 @@
|
||||
"method": "recursive_elimination"
|
||||
},
|
||||
"feature_parameters": {
|
||||
"include_timeframes": ["15m"],
|
||||
"include_timeframes": ["5m"],
|
||||
"include_corr_pairlist": ["BTC/USDT"],
|
||||
"label_period_candles": 10,
|
||||
"include_shifted_candles": 1,
|
||||
"DI_threshold": 0.5,
|
||||
"DI_threshold": 0.3,
|
||||
"weight_factor": 0.9,
|
||||
"principal_component_analysis": false,
|
||||
"use_SVM_to_remove_outliers": false,
|
||||
|
||||
@ -99,6 +99,13 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
dataframe["bb_upperband"] = bollinger["upper"]
|
||||
dataframe["bb_width"] = (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) / dataframe["bb_middleband"]
|
||||
dataframe["bb_pct"] = (dataframe["close"] - dataframe["bb_lowerband"]) / (dataframe["bb_upperband"] - dataframe["bb_lowerband"])
|
||||
|
||||
# 添加更多技术指标
|
||||
dataframe["%-macd"] = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)["macd"]
|
||||
dataframe["%-macdsignal"] = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)["macdsignal"]
|
||||
dataframe["%-adx"] = ta.ADX(dataframe, timeperiod=14)
|
||||
dataframe["%-cci"] = ta.CCI(dataframe, timeperiod=20)
|
||||
dataframe["%-willr"] = ta.WILLR(dataframe, timeperiod=14)
|
||||
|
||||
# 添加成交量相关特征
|
||||
dataframe["volume_ma"] = dataframe["volume"].rolling(window=20).mean()
|
||||
@ -170,16 +177,20 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
|
||||
try:
|
||||
label_period = self.freqai_info["feature_parameters"]["label_period_candles"]
|
||||
|
||||
# 生成更复杂的目标变量 up_or_down
|
||||
dataframe["up_or_down"] = np.where(
|
||||
dataframe["close"].shift(-label_period) > dataframe["close"], 1, 0
|
||||
)
|
||||
|
||||
# 生成 %-volatility 特征
|
||||
dataframe["%-volatility"] = dataframe["close"].pct_change().rolling(20).std()
|
||||
|
||||
# 单一回归目标
|
||||
# 移除对未来的数据依赖
|
||||
# 确保 &-buy_rsi 列的值计算正确
|
||||
dataframe["&-buy_rsi"] = ta.RSI(dataframe, timeperiod=14)
|
||||
|
||||
# 数据清理
|
||||
for col in ["&-buy_rsi"]:
|
||||
for col in ["&-buy_rsi", "up_or_down", "%-volatility"]:
|
||||
# 使用直接操作避免链式赋值
|
||||
dataframe[col] = dataframe[col].replace([np.inf, -np.inf], np.nan)
|
||||
dataframe[col] = dataframe[col].ffill() # 替代 fillna(method='ffill')
|
||||
@ -187,19 +198,11 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
if dataframe[col].isna().any():
|
||||
logger.warning(f"目标列 {col} 仍包含 NaN,填充为默认值")
|
||||
|
||||
# 数据清理
|
||||
for col in ["&-buy_rsi", "%-volatility"]:
|
||||
# 使用直接操作避免链式赋值
|
||||
dataframe[col] = dataframe[col].replace([np.inf, -np.inf], 0)
|
||||
dataframe[col] = dataframe[col].ffill() # 替代 fillna(method='ffill')
|
||||
dataframe[col] = dataframe[col].fillna(0)
|
||||
if dataframe[col].isna().any():
|
||||
logger.warning(f"目标列 {col} 仍包含 NaN,检查数据生成逻辑")
|
||||
except Exception as e:
|
||||
logger.error(f"创建 FreqAI 目标失败:{str(e)}")
|
||||
raise
|
||||
|
||||
logger.info(f"目标列预览:\n{dataframe[['&-buy_rsi']].head().to_string()}")
|
||||
logger.info(f"目标列预览:\n{dataframe[['up_or_down', '&-buy_rsi']].head().to_string()}")
|
||||
return dataframe
|
||||
|
||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
@ -237,13 +240,13 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
dataframe[col] = dataframe[col].fillna(-0.1 if col == "&-stoploss" else 0)
|
||||
|
||||
# 简化动态参数生成逻辑
|
||||
# 简化 buy_rsi 和 sell_rsi 的生成逻辑
|
||||
# 放松 buy_rsi 和 sell_rsi 的生成逻辑
|
||||
# 计算 buy_rsi_pred 并清理 NaN 值
|
||||
dataframe["buy_rsi_pred"] = dataframe["&-buy_rsi"].rolling(window=10).mean().clip(20, 40)
|
||||
dataframe["buy_rsi_pred"] = dataframe["&-buy_rsi"].rolling(window=10).mean().clip(30, 50)
|
||||
dataframe["buy_rsi_pred"] = dataframe["buy_rsi_pred"].fillna(dataframe["buy_rsi_pred"].mean())
|
||||
|
||||
# 计算 sell_rsi_pred 并清理 NaN 值
|
||||
dataframe["sell_rsi_pred"] = dataframe["buy_rsi_pred"] + 20
|
||||
dataframe["sell_rsi_pred"] = dataframe["buy_rsi_pred"] + 40
|
||||
dataframe["sell_rsi_pred"] = dataframe["sell_rsi_pred"].fillna(dataframe["sell_rsi_pred"].mean())
|
||||
|
||||
# 计算 stoploss_pred 并清理 NaN 值
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user