with v3
This commit is contained in:
parent
ed011ef498
commit
e27cde2e19
@ -77,7 +77,10 @@
|
||||
"live_retrain_hours": 0,
|
||||
"feature_selection": {
|
||||
"method": "recursive_elimination",
|
||||
"threshold": 0.01
|
||||
"threshold": 0.01,
|
||||
"steps": 1,
|
||||
"cv": 5,
|
||||
"n_features_to_select": null
|
||||
},
|
||||
"feature_parameters": {
|
||||
"include_timeframes": ["3m", "5m", "1h"],
|
||||
@ -93,8 +96,8 @@
|
||||
"random_state": 42
|
||||
},
|
||||
"model_training_parameters": {
|
||||
"n_estimators": 200,
|
||||
"learning_rate": 0.05,
|
||||
"n_estimators": 100,
|
||||
"learning_rate": 0.1,
|
||||
"max_depth": 5,
|
||||
"subsample": 0.8,
|
||||
"colsample_bytree": 0.8,
|
||||
|
||||
@ -72,18 +72,27 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
}
|
||||
|
||||
def featcaure_engineering_expand_all(self, dataframe: DataFrame, period: int, metadata: dict, **kwargs) -> DataFrame:
|
||||
# 保留关键的技术指标
|
||||
dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)
|
||||
# 只计算必要的技术指标
|
||||
if len(dataframe) > 14:
|
||||
dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)
|
||||
dataframe["ema_12"] = ta.EMA(dataframe, timeperiod=12)
|
||||
dataframe["ema_26"] = ta.EMA(dataframe, timeperiod=26)
|
||||
else:
|
||||
dataframe["rsi"] = 50
|
||||
dataframe["ema_12"] = dataframe["close"]
|
||||
dataframe["ema_26"] = dataframe["close"]
|
||||
|
||||
# 确保 MACD 列被正确计算并保留
|
||||
try:
|
||||
# 确保有足够的数据计算 MACD
|
||||
if len(dataframe) >= 50:
|
||||
macd = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)
|
||||
dataframe["macd"] = macd["macd"]
|
||||
dataframe["macdsignal"] = macd["macdsignal"]
|
||||
except Exception as e:
|
||||
logger.error(f"计算 MACD 列时出错:{str(e)}")
|
||||
dataframe["macd"] = np.nan
|
||||
dataframe["macdsignal"] = np.nan
|
||||
dataframe["macdhist"] = macd["macdhist"]
|
||||
else:
|
||||
dataframe["macd"] = 0
|
||||
dataframe["macdsignal"] = 0
|
||||
dataframe["macdhist"] = 0
|
||||
|
||||
# 检查 MACD 列是否存在
|
||||
if "macd" not in dataframe.columns or "macdsignal" not in dataframe.columns:
|
||||
@ -148,9 +157,12 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
label_period = self.freqai_info["feature_parameters"]["label_period_candles"]
|
||||
|
||||
# 定义目标变量为未来价格变化百分比(连续值)
|
||||
dataframe["up_or_down"] = (
|
||||
dataframe["close"].shift(-label_period) - dataframe["close"]
|
||||
) / dataframe["close"]
|
||||
# 使用对数收益率作为目标变量
|
||||
dataframe["target"] = np.log(
|
||||
dataframe["close"].shift(-label_period) / dataframe["close"]
|
||||
)
|
||||
# 处理异常值
|
||||
dataframe["target"] = dataframe["target"].clip(-0.1, 0.1)
|
||||
|
||||
# 数据清理:处理 NaN 和 Inf 值
|
||||
dataframe["up_or_down"] = dataframe["up_or_down"].replace([np.inf, -np.inf], np.nan)
|
||||
@ -225,9 +237,9 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
|
||||
# 简化动态参数生成逻辑
|
||||
# 放松 buy_rsi 和 sell_rsi 的生成逻辑
|
||||
# 计算 buy_rsi_pred 并清理 NaN 值
|
||||
dataframe["buy_rsi_pred"] = dataframe["rsi"].rolling(window=10).mean().clip(30, 50)
|
||||
dataframe["buy_rsi_pred"] = dataframe["buy_rsi_pred"].fillna(dataframe["buy_rsi_pred"].median())
|
||||
# 使用固定 RSI 阈值
|
||||
self.buy_rsi.value = 30
|
||||
self.sell_rsi.value = 70
|
||||
|
||||
# 计算 sell_rsi_pred 并清理 NaN 值
|
||||
dataframe["sell_rsi_pred"] = dataframe["buy_rsi_pred"] + 20
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user