Hyperopt参数优化

This commit is contained in:
zhangkun 2025-12-06 10:17:11 +08:00
parent 0e4480d383
commit b970eaf47c
4 changed files with 161 additions and 68 deletions

View File

@ -1,19 +1,7 @@
{
"strategy_name": "FreqaiPrimer",
"export_time": "2025-12-03 00:03:56.464370+00:00",
"ft_stratparam_v": 1,
"params": {
"roi": {},
"stoploss": {
"stoploss": -0.085
},
"trailing": {
"trailing_stop": true,
"trailing_stop_positive": 0.012,
"trailing_stop_positive_offset": 0.025,
"trailing_only_offset_is_reached": true
},
"max_open_trades": {
"max_open_trades": 5
},
"buy": {
"add_bb_lower_proximity": 0.871,
"add_position_callback": 0.057,
@ -21,9 +9,9 @@
"add_rsi_oversold_threshold": 37,
"add_stochrsi_oversold": 14,
"adjust_multiplier": 0.87,
"bb_length": 58,
"bb_lower_deviation": 0.931,
"bb_std": 4.4,
"bb_length": 31,
"bb_lower_deviation": 1.143,
"bb_std": 2.53,
"bb_width_threshold": 0.016,
"h1_max_candles": 40,
"h1_max_consecutive_candles": 1,
@ -31,12 +19,17 @@
"max_entry_adjustments": 6,
"min_condition_count": 2,
"rsi_bull_threshold": 44,
"rsi_length": 30,
"rsi_length": 17,
"rsi_oversold": 27,
"stochrsi_bull_threshold": 33,
"stochrsi_bull_threshold": 47,
"stochrsi_neutral_threshold": 18,
"volume_multiplier": 3.4
"volume_multiplier": 2.6
},
"max_open_trades": {
"max_open_trades": 5
},
"protection": {},
"roi": {},
"sell": {
"exit_bb_upper_deviation": 0.913,
"exit_profit_tier1": 0.034,
@ -49,8 +42,17 @@
"reduce_coefficient": 0.229,
"reduce_profit_base": 0.02
},
"protection": {}
"stoploss": {
"stoploss": -0.085
},
"trailing": {
"trailing_only_offset_is_reached": true,
"trailing_stop": true,
"trailing_stop_positive": 0.012,
"trailing_stop_positive_offset": 0.025
}
},
"ft_stratparam_v": 1,
"export_time": "2025-12-03 00:03:56.464370+00:00"
"strategy_name": "FreqaiPrimer",
"trailing_only_offset_is_reached": false,
"trailing_stop": false
}

View File

@ -81,50 +81,52 @@ class FreqaiPrimer(IStrategy):
timeframe = "3m" # 主时间框架为 3 分钟
can_short = False # 禁用做空
# [propertiesGrp_List]--------------------------------------------------------------------------------------------------------------------------------------
# [propertiesGrp step="1" name="第一轮优化" epochs="160" space="buy" description="入场基础条件优化,入场确认条件优化"]
bb_std = DecimalParameter(2.0, 6.0, decimals=2, default=3.2, optimize=True, load=True, space='buy') # 安全2.0-5.0
rsi_length = IntParameter(10, 30, default=30, optimize=True, load=True, space='buy') # 安全10-30
bb_lower_deviation = DecimalParameter(0.92, 1.15, decimals=3, default=1.006, optimize=True, load=True, space='buy') # 安全0.92-1.15
stochrsi_bull_threshold = IntParameter(20, 50, default=48, optimize=True, load=True, space='buy') # 安全20-50
volume_multiplier = DecimalParameter(1.5, 6.0, decimals=1, default=3.6, optimize=True, load=True, space='buy') # 安全1.5-6.0
min_condition_count = IntParameter(1, 2, default=2, optimize=True, load=True, space='buy') # 最多只允许2个条件
bb_length = IntParameter(20, 60, default=21, optimize=True, load=True, space='buy') # 安全20-60
# [/propertiesGrp]
# [propertiesGrp_List]
# [propertiesGrp step="2" name="第二轮优化 - 剧烈拉升检测" epochs="240" space="buy" description="防追高核心参数,绝对不能放宽!"]
rsi_oversold = IntParameter(20, 50, default=23, optimize=True, load=True, space='buy') # 安全20-50
rsi_bull_threshold = IntParameter(40, 68, default=45, optimize=True, load=True, space='buy') # 安全40-68
stochrsi_neutral_threshold = IntParameter(15, 40, default=16, optimize=True, load=True, space='buy') # 安全15-40
bb_width_threshold = DecimalParameter(0.003, 0.030, decimals=3, default=0.011, optimize=True, load=True, space='buy') # 安全0.003-0.030
h1_max_candles = IntParameter(16, 50, default=19, optimize=True, load=True, space='buy') # 黄金区间绝不能超过50
h1_rapid_rise_threshold = DecimalParameter(0.08, 0.22, decimals=3, default=0.192, optimize=True, load=True, space='buy') # 0.08-0.22 实盘最稳
h1_max_consecutive_candles = IntParameter(1, 2, default=1, optimize=True, load=True, space='buy') # 固定为1最稳2也行
# [/propertiesGrp]
# [propertiesGrp step="1" name="第一轮优化" space="buy" epochs="160" description="入场基础条件优化,入场确认条件优化"]
bb_length=IntParameter(20, 60, optimize=True, load=True, default=21, space='buy') # [PARAM]
bb_lower_deviation=DecimalParameter(0.92, 1.15, decimals=3, optimize=True, load=True, default=1.006, space='buy') # [PARAM]
bb_std=DecimalParameter(2, 6, decimals=2, optimize=True, load=True, default=3.2, space='buy') # [PARAM]
min_condition_count=IntParameter(1, 2, optimize=True, load=True, default=2, space='buy') # [PARAM]
rsi_length=IntParameter(10, 30, optimize=True, load=True, default=30, space='buy') # [PARAM]
stochrsi_bull_threshold=IntParameter(20, 50, optimize=True, load=True, default=48, space='buy') # [PARAM]
volume_multiplier=DecimalParameter(1.5, 6, decimals=1, optimize=True, load=True, default=3.6, space='buy') # [PARAM]
# [/propertiesGrp]
# [propertiesGrp step="3" name="第三轮优化 - 加仓策略" epochs="220" space="buy" description="加仓精准度与金额管理,严防爆仓"]
add_position_callback = DecimalParameter(0.047, 0.090, decimals=3, default=0.067, optimize=True, load=True, space='buy') # 2.5%-7.0% 回调才加
add_rsi_oversold_threshold = IntParameter(15, 40, default=23, optimize=True, load=True, space='buy') # 不能太低
add_stochrsi_oversold = IntParameter(10, 35, default=23, optimize=True, load=True, space='buy')
add_bb_lower_proximity = DecimalParameter(0.85, 1.20, decimals=3, default=0.987, optimize=True, load=True, space='buy') # 不能离下轨太远
add_position_decrease_ratio= DecimalParameter(0.30, 0.80, decimals=2, default=0.55, optimize=True, load=True, space='buy') # 递减比例别太激进
max_entry_adjustments = IntParameter(2, 7, default=6, optimize=True, load=True, space='buy') # 最多7次加仓防爆仓
adjust_multiplier = DecimalParameter(0.6, 1.6, decimals=2, default=0.98, optimize=True, load=True, space='buy') # 别让加仓金额指数爆炸
# [/propertiesGrp]
# [propertiesGrp step="2" name="第二轮优化 - 剧烈拉升检测" space="buy" epochs="240" description="防追高核心参数,绝对不能放宽!"]
bb_width_threshold=DecimalParameter(0.003, 0.03, decimals=3, optimize=True, load=True, default=0.011, space='buy') # [PARAM]
h1_max_candles=IntParameter(16, 50, optimize=True, load=True, default=19, space='buy') # [PARAM]
h1_max_consecutive_candles=IntParameter(1, 2, optimize=True, load=True, default=1, space='buy') # [PARAM]
h1_rapid_rise_threshold=DecimalParameter(0.08, 0.22, decimals=3, optimize=True, load=True, default=0.192, space='buy') # [PARAM]
rsi_bull_threshold=IntParameter(40, 68, optimize=True, load=True, default=45, space='buy') # [PARAM]
rsi_oversold=IntParameter(20, 50, optimize=True, load=True, default=23, space='buy') # [PARAM]
stochrsi_neutral_threshold=IntParameter(15, 40, optimize=True, load=True, default=16, space='buy') # [PARAM]
# [/propertiesGrp]
# [propertiesGrp step="4" name="第四轮优化 - 出场与分级止盈" epochs="200" space="sell" description="出场条件与分级止盈,减仓与风险管理"]
exit_bb_upper_deviation = DecimalParameter(0.90, 1.15, decimals=3, default=0.919, optimize=True, load=True, space='sell')
exit_volume_multiplier = DecimalParameter(2.0, 7.0, decimals=1, default=2.2, optimize=True, load=True, space='sell')
exit_rsi_threshold = IntParameter(55, 72, default=57, optimize=True, load=True, space='sell') # 牛市也能出得了场
exit_profit_tier1 = DecimalParameter(0.03, 0.12, decimals=3, default=0.116, optimize=True, load=True, space='sell')
exit_reduce_tier1 = DecimalParameter(0.20, 0.70, decimals=2, default=0.21, optimize=True, load=True, space='sell')
exit_profit_tier2 = DecimalParameter(0.08, 0.20, decimals=3, default=0.152, optimize=True, load=True, space='sell')
exit_reduce_tier2 = DecimalParameter(0.15, 0.60, decimals=2, default=0.17, optimize=True, load=True, space='sell')
reduce_profit_base = DecimalParameter(0.02, 0.12, decimals=3, default=0.081, optimize=True, load=True, space='sell')
reduce_coefficient = DecimalParameter(0.15, 0.55, decimals=3, default=0.326, optimize=True, load=True, space='sell')
max_reduce_adjustments = IntParameter(1, 4, default=2, optimize=True, load=True, space='sell') # 最多4次减仓就够了
# [/propertiesGrp]
# [/propertiesGrp_List]-----------------------------------------------------------------------------------------------------------------------------
# [propertiesGrp step="3" name="第三轮优化 - 加仓策略" space="buy" epochs="220" description="加仓精准度与金额管理,严防爆仓"]
add_bb_lower_proximity=DecimalParameter(0.85, 1.2, decimals=3, optimize=True, load=True, default=0.987, space='buy') # [PARAM]
add_position_callback=DecimalParameter(0.047, 0.09, decimals=3, optimize=True, load=True, default=0.067, space='buy') # [PARAM]
add_position_decrease_ratio=DecimalParameter(0.3, 0.8, decimals=2, optimize=True, load=True, default=0.55, space='buy') # [PARAM]
add_rsi_oversold_threshold=IntParameter(15, 40, optimize=True, load=True, default=23, space='buy') # [PARAM]
add_stochrsi_oversold=IntParameter(10, 35, optimize=True, load=True, default=23, space='buy') # [PARAM]
adjust_multiplier=DecimalParameter(0.6, 1.6, decimals=2, optimize=True, load=True, default=0.98, space='buy') # [PARAM]
max_entry_adjustments=IntParameter(2, 7, optimize=True, load=True, default=6, space='buy') # [PARAM]
# [/propertiesGrp]
# [propertiesGrp step="4" name="第四轮优化 - 出场与分级止盈" space="sell" epochs="200" description="出场条件与分级止盈,减仓与风险管理"]
exit_bb_upper_deviation=DecimalParameter(0.9, 1.15, decimals=3, optimize=True, load=True, default=0.919, space='sell') # [PARAM]
exit_profit_tier1=DecimalParameter(0.03, 0.12, decimals=3, optimize=True, load=True, default=0.116, space='sell') # [PARAM]
exit_profit_tier2=DecimalParameter(0.08, 0.2, decimals=3, optimize=True, load=True, default=0.152, space='sell') # [PARAM]
exit_reduce_tier1=DecimalParameter(0.2, 0.7, decimals=2, optimize=True, load=True, default=0.21, space='sell') # [PARAM]
exit_reduce_tier2=DecimalParameter(0.15, 0.6, decimals=2, optimize=True, load=True, default=0.17, space='sell') # [PARAM]
exit_rsi_threshold=IntParameter(55, 72, optimize=True, load=True, default=57, space='sell') # [PARAM]
exit_volume_multiplier=DecimalParameter(2, 7, decimals=1, optimize=True, load=True, default=2.2, space='sell') # [PARAM]
max_reduce_adjustments=IntParameter(1, 4, optimize=True, load=True, default=2, space='sell') # [PARAM]
reduce_coefficient=DecimalParameter(0.15, 0.55, decimals=3, optimize=True, load=True, default=0.326, space='sell') # [PARAM]
reduce_profit_base=DecimalParameter(0.02, 0.12, decimals=3, optimize=True, load=True, default=0.081, space='sell') # [PARAM]
# [/propertiesGrp]
# [/propertiesGrp_List]
def informative_pairs(self):
pairs = self.dp.current_whitelist()

70
jsons/best_backtest.json Normal file
View File

@ -0,0 +1,70 @@
{
"id": "L2HZlGdfHkbn",
"vmName": "rose",
"startTime": "2025-12-06T01:17:25.45872627Z",
"endTime": "2025-12-06T02:17:25.45872632Z",
"fullHyperoptEventID": "qavF4D2xpVcl",
"propertyGroupListID": "pglist-h1rcWYd9J5nW3wcL-PzBfYvSVWqlWY0yy-6xTJoXIfYhu2Ykqq-VzDm8zc4MSfna9hS",
"backTestResult": {
"task_id": "qavF4D2xpVcl",
"start_time": "2025-12-06T01:17:25.458718575Z",
"end_time": "2025-12-06T02:17:25.458718816Z",
"performance": {
"total_profit": 0.0092,
"win_rate": 0.8333333333333334,
"max_drawdown": 0.008,
"calmar_ratio": 438.12,
"sharpe_ratio": 31.02,
"sqn": 1.59,
"trades": 25,
"profit_factor": 2.13,
"expectancy": 0.74,
"total_days": 0,
"avg_trade_duration": 0,
"cagr": 0.9511,
"market_change": 0.0032,
"best_pair": "WCT/USDT",
"best_pair_profit": 0.0038,
"worst_pair": "TON/USDT",
"worst_pair_profit": -0.0013
},
"full_hyperopt_event_id": "qavF4D2xpVcl",
"parameters": {
"add_bb_lower_proximity": "0.873",
"add_position_callback": "0.05",
"add_position_decrease_ratio": "0.72",
"add_rsi_oversold_threshold": "31",
"add_stochrsi_oversold": "20",
"adjust_multiplier": "1.51",
"bb_length": "31",
"bb_lower_deviation": "1.143",
"bb_std": "2.53",
"bb_width_threshold": "0.022",
"exit_bb_upper_deviation": "1.021",
"exit_profit_tier1": "0.032",
"exit_profit_tier2": "0.118",
"exit_reduce_tier1": "0.6",
"exit_reduce_tier2": "0.6",
"exit_rsi_threshold": "69",
"exit_volume_multiplier": "3.5",
"h1_max_candles": "24",
"h1_max_consecutive_candles": "2",
"h1_rapid_rise_threshold": "0.199",
"max_entry_adjustments": "4",
"max_reduce_adjustments": "4",
"min_condition_count": "2",
"reduce_coefficient": "0.546",
"reduce_profit_base": "0.082",
"rsi_bull_threshold": "49",
"rsi_length": "17",
"rsi_oversold": "26",
"stochrsi_bull_threshold": "47",
"stochrsi_neutral_threshold": "22",
"volume_multiplier": "2.6"
},
"type": "postTest",
"property_group_list_id": ""
},
"backTestStartTime": "2025-10-17T00:00:00Z",
"backTestEndTime": "2025-10-22T00:00:00Z"
}

View File

@ -0,0 +1,19 @@
{
"total_profit": 0.0092,
"win_rate": 0.8333333333333334,
"max_drawdown": 0.008,
"calmar_ratio": 438.12,
"sharpe_ratio": 31.02,
"sqn": 1.59,
"trades": 25,
"profit_factor": 2.13,
"expectancy": 0.74,
"total_days": 0,
"avg_trade_duration": 0,
"cagr": 0.9511,
"market_change": 0.0032,
"best_pair": "WCT/USDT",
"best_pair_profit": 0.0038,
"worst_pair": "TON/USDT",
"worst_pair_profit": -0.0013
}