up
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
b72587ed6a
commit
456ae1fde0
5
### **4. 测试优化后的策略**
Normal file
5
### **4. 测试优化后的策略**
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
freqtrade backtesting --strategy FreqaiExampleStrategy --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --timerange 20230101-20230401
|
||||
>>>>>>> Snippet
|
||||
@ -42,9 +42,9 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
"shuffle": False,
|
||||
},
|
||||
"model_training_parameters": {
|
||||
"n_estimators": 100,
|
||||
"learning_rate": 0.1,
|
||||
"num_leaves": 31,
|
||||
"n_estimators": 200, # 增加树的数量以提升模型复杂度
|
||||
"learning_rate": 0.05, # 降低学习率以避免过拟合
|
||||
"num_leaves": 50, # 增加叶子节点数量以捕捉更多细节
|
||||
"verbose": -1,
|
||||
},
|
||||
}
|
||||
@ -157,8 +157,9 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
dataframe["&-roi_0"] = (dataframe["close"] / dataframe["close"].shift(label_period) - 1).clip(0, 0.2)
|
||||
|
||||
# 简化动态参数生成逻辑
|
||||
dataframe["buy_rsi_pred"] = dataframe["&-buy_rsi"].clip(10, 50)
|
||||
dataframe["sell_rsi_pred"] = dataframe["&-buy_rsi"] + 30
|
||||
# 简化 buy_rsi 和 sell_rsi 的生成逻辑
|
||||
dataframe["buy_rsi_pred"] = dataframe["&-buy_rsi"].rolling(window=10).mean().clip(20, 40)
|
||||
dataframe["sell_rsi_pred"] = dataframe["buy_rsi_pred"] + 20
|
||||
dataframe["stoploss_pred"] = -0.1 - (dataframe["%-volatility"] * 10).clip(0, 0.25)
|
||||
dataframe["roi_0_pred"] = dataframe["&-roi_0"].clip(0.01, 0.2)
|
||||
|
||||
@ -175,15 +176,17 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
# 设置策略级参数
|
||||
self.buy_rsi.value = float(dataframe["buy_rsi_pred"].iloc[-1])
|
||||
self.sell_rsi.value = float(dataframe["sell_rsi_pred"].iloc[-1])
|
||||
self.stoploss = float(self.stoploss_param.value)
|
||||
# 更保守的止损设置
|
||||
self.stoploss = -0.15 # 固定止损 15%
|
||||
self.minimal_roi = {
|
||||
0: float(self.roi_0.value),
|
||||
15: float(self.roi_15.value),
|
||||
30: float(self.roi_30.value),
|
||||
60: 0
|
||||
}
|
||||
self.trailing_stop_positive = float(dataframe["trailing_stop_positive"].iloc[-1])
|
||||
self.trailing_stop_positive_offset = float(dataframe["trailing_stop_positive_offset"].iloc[-1])
|
||||
# 更保守的追踪止损设置
|
||||
self.trailing_stop_positive = 0.05 # 追踪止损触发点
|
||||
self.trailing_stop_positive_offset = 0.1 # 追踪止损偏移量
|
||||
|
||||
logger.info(f"动态参数:buy_rsi={self.buy_rsi.value}, sell_rsi={self.sell_rsi.value}, "
|
||||
f"stoploss={self.stoploss}, trailing_stop_positive={self.trailing_stop_positive}")
|
||||
@ -198,10 +201,12 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
return dataframe
|
||||
|
||||
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
enter_long_conditions = [
|
||||
qtpylib.crossed_above(df["rsi"], df["buy_rsi_pred"]),
|
||||
df["volume"] > 0
|
||||
]
|
||||
# 改进买入信号条件
|
||||
enter_long_conditions = [
|
||||
(df["rsi"] < df["buy_rsi_pred"]) & (df["rsi"].shift(1) >= df["buy_rsi_pred"]), # RSI 下穿买入阈值
|
||||
df["volume"] > df["volume"].rolling(window=10).mean(), # 成交量高于近期均值
|
||||
df["close"] > df["bb_middleband"] # 价格高于布林带中轨
|
||||
]
|
||||
if enter_long_conditions:
|
||||
df.loc[
|
||||
reduce(lambda x, y: x & y, enter_long_conditions),
|
||||
@ -210,10 +215,12 @@ class FreqaiExampleStrategy(IStrategy):
|
||||
return df
|
||||
|
||||
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
exit_long_conditions = [
|
||||
qtpylib.crossed_above(df["rsi"], df["sell_rsi_pred"]),
|
||||
df["volume"] > 0
|
||||
]
|
||||
# 改进卖出信号条件
|
||||
exit_long_conditions = [
|
||||
(df["rsi"] > df["sell_rsi_pred"]) & (df["rsi"].shift(1) <= df["sell_rsi_pred"]), # RSI 上穿卖出阈值
|
||||
df["volume"] > df["volume"].rolling(window=10).mean(), # 成交量高于近期均值
|
||||
df["close"] < df["bb_middleband"] # 价格低于布林带中轨
|
||||
]
|
||||
if exit_long_conditions:
|
||||
df.loc[
|
||||
reduce(lambda x, y: x & y, exit_long_conditions),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user