result12.md
This commit is contained in:
parent
8dfbdc254f
commit
e2b7fe5dcf
2220
chat/result12.md
Normal file
2220
chat/result12.md
Normal file
File diff suppressed because it is too large
Load Diff
@ -37,7 +37,7 @@
|
||||
"rateLimit": 3000,
|
||||
"timeout": 20000
|
||||
},
|
||||
"pair_whitelist": ["BTC/USDT", "ETH/USDT", "SOL/USDT", "DOT/USDT", "OKB/USDT", "TON/USDT"],
|
||||
"pair_whitelist": ["BTC/USDT", "TON/USDT", "DOT/USDT", "XRP/USDT", "OKB/USDT", "SOL/USDT", "DOGE/USDT", "WCT/USDT", "TRUMP/USDT", "SUI/USDT", "PEPE/USDT", "TRB/USDT", "MASK/USDT", "UNI/USDT", "KAITO/USDT"],
|
||||
"pair_blacklist": []
|
||||
},
|
||||
"entry_pricing": {
|
||||
|
||||
@ -12,16 +12,18 @@
|
||||
},
|
||||
"protection": {},
|
||||
"roi": {
|
||||
"0": 0.17099999999999999,
|
||||
"8": 0.022,
|
||||
"14": 0.014,
|
||||
"0": 0.07,
|
||||
"6": 0.022,
|
||||
"12": 0.01,
|
||||
"21": 0
|
||||
},
|
||||
"stoploss": {
|
||||
"stoploss": -0.075
|
||||
},
|
||||
"trailing": {
|
||||
"trailing_stop": false
|
||||
"trailing_stop": true,
|
||||
"trailing_stop_positive": 0.01,
|
||||
"trailing_stop_positive_offset": 0.015
|
||||
}
|
||||
},
|
||||
"ft_stratparam_v": 1,
|
||||
|
||||
@ -18,8 +18,30 @@ class FreqaiPrimer(IStrategy):
|
||||
- 不使用 Hyperopt 优化任何参数
|
||||
- 使用 FreqAI 提供的趋势和波动率信号进行交易决策
|
||||
"""
|
||||
# 👇 添加在这里
|
||||
PAIR_PARAMS = {
|
||||
"BTC/USDT": {"volatility_factor": 1.0, "min_stop": -0.005},
|
||||
"TON/USDT": {"volatility_factor": 1.3, "min_stop": -0.0035},
|
||||
"DOGE/USDT": {"volatility_factor": 1.5, "min_stop": -0.003},
|
||||
"DOT/USDT": {"volatility_factor": 1.3, "min_stop": -0.0035},
|
||||
"XRP/USDT": {"volatility_factor": 1.35, "min_stop": -0.0032},
|
||||
"OKB/USDT": {"volatility_factor": 0.9, "min_stop": -0.006},
|
||||
"SOL/USDT": {"volatility_factor": 1.4, "min_stop": -0.0032},
|
||||
"WCT/USDT": {"volatility_factor": 1.4, "min_stop": -0.004},
|
||||
"TRUMP/USDT": {"volatility_factor": 1.4, "min_stop": -0.0035},
|
||||
"SUI/USDT": {"volatility_factor": 1.6, "min_stop": -0.0025},
|
||||
"PEPE/USDT": {"volatility_factor": 1.5, "min_stop": -0.0036},
|
||||
"TRB/USDT": {"volatility_factor": 1.45, "min_stop": -0.004},
|
||||
"MASK/USDT": {"volatility_factor": 1.65, "min_stop": -0.0045},
|
||||
"UNI/USDT": {"volatility_factor": 1.45, "min_stop": -0.005},
|
||||
"KAITO/USDT": {"volatility_factor": 1.45, "min_stop": -0.004},
|
||||
}
|
||||
|
||||
use_custom_stoploss = True
|
||||
trailing_stop = True
|
||||
trailing_stop_positive = 0.005
|
||||
trailing_stop_positive_offset = 0.01
|
||||
trailing_only_offset_is_reached = True
|
||||
plot_config = {
|
||||
"main_plot": {},
|
||||
"subplots": {
|
||||
@ -115,7 +137,21 @@ class FreqaiPrimer(IStrategy):
|
||||
# 4. 动态止损目标:基于波动率缩放
|
||||
dataframe["&-stoploss_target"] = -dataframe["&-volatility_forecast"] * 1.2
|
||||
|
||||
# 5. 市场状态识别:判断当前是震荡、趋势、超买还是超卖
|
||||
# 👇 新增:z-score 标准化模型输出
|
||||
if self.freqai and hasattr(self.freqai, "data"):
|
||||
labels_mean = self.freqai.data.labels_mean
|
||||
labels_std = self.freqai.data.labels_std
|
||||
|
||||
mean_roi = labels_mean.get("&-roi_target", 0.01)
|
||||
std_roi = labels_std.get("&-roi_target", 0.01)
|
||||
mean_stop = labels_mean.get("&-stoploss_target", -0.01)
|
||||
std_stop = labels_std.get("&-stoploss_target", 0.01)
|
||||
|
||||
# z-score 标准化
|
||||
dataframe["&-roi_target_z"] = (dataframe["&-roi_target"] - mean_roi) / std_roi
|
||||
dataframe["&-stoploss_target_z"] = (dataframe["&-stoploss_target"] - mean_stop) / std_stop
|
||||
|
||||
# 市场状态识别:判断当前是震荡、趋势、超买还是超卖
|
||||
if "bb_upperband-period" in dataframe.columns and "bb_lowerband-period" in dataframe.columns:
|
||||
dataframe["&-market_condition"] = np.select([
|
||||
(dataframe["close"] > dataframe["bb_upperband-period"]),
|
||||
@ -133,7 +169,6 @@ class FreqaiPrimer(IStrategy):
|
||||
# 卖出信号(必须存在)
|
||||
dataframe["&-sell_signal"] = np.where(dataframe["&-trend_strength"] < -0.01, 1, 0)
|
||||
|
||||
|
||||
return dataframe
|
||||
|
||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
@ -143,11 +178,22 @@ class FreqaiPrimer(IStrategy):
|
||||
# FreqAI 提供的预测列
|
||||
if "&-trend" in dataframe.columns:
|
||||
dataframe["in_uptrend"] = dataframe["&-trend"] > 0.5
|
||||
|
||||
# 将 roi_target 存入 dataframe,供后续使用
|
||||
if "&-roi_target" in dataframe.columns:
|
||||
dataframe["&-roi_target"] = dataframe["&-roi_target"].ffill().fillna(0.01)
|
||||
else:
|
||||
dataframe["&-roi_target"] = 0.01
|
||||
|
||||
# 添加 trailing stop 参数到 dataframe
|
||||
if "&-volatility_forecast" in dataframe.columns:
|
||||
volatility = dataframe["&-volatility_forecast"].iloc[-1]
|
||||
dataframe["trailing_stop_positive"] = max(0.003, volatility * 0.5)
|
||||
dataframe["trailing_stop_positive_offset"] = max(0.006, volatility * 1.0)
|
||||
else:
|
||||
dataframe["trailing_stop_positive"] = 0.005
|
||||
dataframe["trailing_stop_positive_offset"] = 0.01
|
||||
|
||||
return dataframe
|
||||
|
||||
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
|
||||
@ -158,13 +204,13 @@ class FreqaiPrimer(IStrategy):
|
||||
df["buy_threshold"] = df["&-buy_signal"].rolling(20).quantile(0.8)
|
||||
buy_condition = (df["&-buy_signal"] >= df["buy_threshold"]) & (df["&-buy_signal"] > 0.4)
|
||||
|
||||
# 动态计算趋势强度的滚动均值和标准差
|
||||
# 👇 新增:滚动 Z-score 趋势判断
|
||||
window = 50
|
||||
df["trend_mean"] = df["&-trend_strength"].rolling(window).mean()
|
||||
df["trend_std"] = df["&-trend_strength"].rolling(window).std()
|
||||
|
||||
# 使用 z-score 判断趋势是否显著
|
||||
df["z_score_trend"] = (df["&-trend_strength"] - df["trend_mean"]) / df["trend_std"]
|
||||
|
||||
# 只有当 z-score > 1 时才认为趋势显著
|
||||
buy_condition &= (df["z_score_trend"] > 1)
|
||||
|
||||
# 打印模型统计信息用于调试
|
||||
@ -232,30 +278,43 @@ class FreqaiPrimer(IStrategy):
|
||||
# 获取预测的 ROI 目标
|
||||
roi_target = last_candle.get("&-roi_target", 0.01)
|
||||
|
||||
# 获取模型输出统计信息用于自适应判断
|
||||
mean_roi = 0.01
|
||||
std_roi = 0.01
|
||||
|
||||
if self.freqai and hasattr(self.freqai, "data"):
|
||||
labels_mean = self.freqai.data.labels_mean
|
||||
labels_std = self.freqai.data.labels_std
|
||||
|
||||
mean_roi = labels_mean.get("&-roi_target", mean_roi)
|
||||
std_roi = labels_std.get("&-roi_target", std_roi)
|
||||
|
||||
high_threshold = mean_roi + std_roi
|
||||
low_threshold = mean_roi - std_roi
|
||||
|
||||
# 根据预测值生成新的 ROI 表
|
||||
if roi_target > 0.05:
|
||||
if roi_target > high_threshold:
|
||||
new_minimal_roi = {
|
||||
"0": roi_target * 1.0,
|
||||
"10": roi_target * 0.8,
|
||||
"30": roi_target * 0.5,
|
||||
"60": roi_target * 0.2,
|
||||
"120": 0.01
|
||||
"120": 0.005
|
||||
}
|
||||
elif 0.02 <= roi_target <= 0.05:
|
||||
elif low_threshold <= roi_target <= high_threshold:
|
||||
new_minimal_roi = {
|
||||
"0": roi_target * 1.0,
|
||||
"20": roi_target * 0.7,
|
||||
"60": roi_target * 0.3,
|
||||
"120": 0.01
|
||||
"120": 0.005
|
||||
}
|
||||
else:
|
||||
new_minimal_roi = {
|
||||
"0": max(0.01, roi_target),
|
||||
"60": 0.01,
|
||||
"180": 0.01
|
||||
"0": max(0.005, roi_target),
|
||||
"60": 0.005,
|
||||
"180": 0.005
|
||||
}
|
||||
|
||||
# 返回新的 minimal_roi
|
||||
return new_minimal_roi
|
||||
|
||||
def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,
|
||||
@ -268,10 +327,33 @@ class FreqaiPrimer(IStrategy):
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
last_candle = dataframe.iloc[-1]
|
||||
|
||||
# 获取预测的止损目标
|
||||
stoploss_target = last_candle.get("&-stoploss_target", -0.01)
|
||||
# 获取预测的止损目标(使用 z-score 版本)
|
||||
stoploss_z = last_candle.get("&-stoploss_target_z", -1.0) # 默认值为 -1.0(一个标准差)
|
||||
|
||||
# 将 stoploss_target 转换为负数(因为 stoploss 是负值)
|
||||
dynamic_stoploss = min(-0.005, stoploss_target) # 设置最小止损限制a
|
||||
# 获取模型统计信息用于自适应判断
|
||||
mean_stop = -0.01
|
||||
std_stop = 0.01
|
||||
|
||||
if self.freqai and hasattr(self.freqai, "data"):
|
||||
labels_mean = self.freqai.data.labels_mean
|
||||
labels_std = self.freqai.data.labels_std
|
||||
|
||||
mean_stop = labels_mean.get("&-stoploss_target", mean_stop)
|
||||
std_stop = labels_std.get("&-stoploss_target", std_stop)
|
||||
|
||||
# 获取币种特定参数
|
||||
params = self.PAIR_PARAMS.get(pair, {"volatility_factor": 1.0, "min_stop": -0.005})
|
||||
volatility_factor = params["volatility_factor"]
|
||||
min_stop = params["min_stop"]
|
||||
|
||||
# 动态止损下限 = 平均值 - volatility_factor * 标准差
|
||||
dynamic_min_stop = min(min_stop, mean_stop - volatility_factor * std_stop)
|
||||
|
||||
# 如果 z-score < -1,则说明当前止损偏移较大,适当放宽
|
||||
if stoploss_z < -1.0:
|
||||
dynamic_min_stop = min(dynamic_min_stop * 1.2, -0.003)
|
||||
|
||||
# 最终止损值 = 模型建议值 和 动态下限中的较小者
|
||||
dynamic_stoploss = dynamic_min_stop
|
||||
|
||||
return dynamic_stoploss
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user