跟特征数量没关系
Some checks are pending
Update Docker Hub Description / dockerHubDescription (push) Waiting to run

This commit is contained in:
zhangkun9038@dingtalk.com 2025-04-28 14:07:32 +08:00
parent ea707fe104
commit ec7d7c2842

View File

@ -72,27 +72,13 @@ class FreqaiExampleStrategy(IStrategy):
}
def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, metadata: dict, **kwargs) -> DataFrame:
# 添加更多技术指标
# 保留关键的技术指标
dataframe["%-rsi"] = ta.RSI(dataframe, timeperiod=14)
dataframe["%-mfi"] = ta.MFI(dataframe, timeperiod=14)
dataframe["%-sma"] = ta.SMA(dataframe, timeperiod=20)
dataframe["%-ema"] = ta.EMA(dataframe, timeperiod=20)
dataframe["%-adx"] = ta.ADX(dataframe, timeperiod=14)
dataframe["%-atr"] = ta.ATR(dataframe, timeperiod=14)
dataframe["%-obv"] = ta.OBV(dataframe)
dataframe["%-cci"] = ta.CCI(dataframe, timeperiod=20)
dataframe["%-stoch"] = ta.STOCH(dataframe)['slowk']
dataframe["%-macd"] = ta.MACD(dataframe)['macd']
dataframe["%-macdsignal"] = ta.MACD(dataframe)['macdsignal']
dataframe["%-macdhist"] = ta.MACD(dataframe)['macdhist']
dataframe["%-willr"] = ta.WILLR(dataframe, timeperiod=14)
dataframe["%-ultosc"] = ta.ULTOSC(dataframe)
dataframe["%-trix"] = ta.TRIX(dataframe, timeperiod=14)
dataframe["%-ad"] = ta.ADOSC(dataframe)
dataframe["%-mom"] = ta.MOM(dataframe, timeperiod=10)
dataframe["%-roc"] = ta.ROC(dataframe, timeperiod=10)
# 添加布林带相关特征
macd = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)
dataframe["%-macd"] = macd["macd"]
dataframe["%-macdsignal"] = macd["macdsignal"]
# 保留布林带相关特征
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe["bb_lowerband"] = bollinger["lower"]
dataframe["bb_middleband"] = bollinger["mid"]
@ -100,33 +86,12 @@ class FreqaiExampleStrategy(IStrategy):
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()
dataframe["volume_roc"] = dataframe["volume"].pct_change(periods=10)
dataframe["volume_obv"] = ta.OBV(dataframe)
# 添加价格相关特征
dataframe["close_ma"] = dataframe["close"].rolling(window=20).mean()
# 保留价格变化率
dataframe["close_roc"] = dataframe["close"].pct_change(periods=10)
dataframe["close_log_ret"] = np.log(dataframe["close"]).diff()
dataframe["close_zscore"] = (dataframe["close"] - dataframe["close"].rolling(window=20).mean()) / dataframe["close"].rolling(window=20).std()
# 添加时间相关特征
dataframe["hour"] = dataframe["date"].dt.hour
dataframe["day_of_week"] = dataframe["date"].dt.dayofweek
dataframe["is_weekend"] = dataframe["day_of_week"].isin([5, 6]).astype(int)
# 添加波动率相关特征
dataframe["volatility"] = dataframe["close"].pct_change().rolling(window=20).std()
dataframe["volatility_ma"] = dataframe["volatility"].rolling(window=20).mean()
dataframe["volatility_roc"] = dataframe["volatility"].pct_change(periods=10)
# 改进数据清理
for col in dataframe.columns: