Hyperopt参数优化

This commit is contained in:
zhangkun 2025-12-06 15:46:41 +08:00
parent 0e4480d383
commit b0504384d8
4 changed files with 162 additions and 69 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,22 +9,27 @@
"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": 38,
"bb_lower_deviation": 0.937,
"bb_std": 5.89,
"bb_width_threshold": 0.016,
"h1_max_candles": 40,
"h1_max_consecutive_candles": 1,
"h1_rapid_rise_threshold": 0.166,
"max_entry_adjustments": 6,
"min_condition_count": 2,
"min_condition_count": 1,
"rsi_bull_threshold": 44,
"rsi_length": 30,
"rsi_length": 14,
"rsi_oversold": 27,
"stochrsi_bull_threshold": 33,
"stochrsi_bull_threshold": 43,
"stochrsi_neutral_threshold": 18,
"volume_multiplier": 3.4
"volume_multiplier": 5.4
},
"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 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="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="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_List]
# [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="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="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": "Vb2VXEaACSVF",
"vmName": "rose",
"startTime": "2025-12-06T06:46:55.004449609Z",
"endTime": "2025-12-06T07:46:55.004449649Z",
"fullHyperoptEventID": "hkx4d4r8u4D1",
"propertyGroupListID": "pglist-lX0QQ64Y2YxOujDn-MOa6LxdkkdmcDQrs-DIpUszYeSJ6RA9pj-b0LWHhOimHanPmOc",
"backTestResult": {
"task_id": "hkx4d4r8u4D1",
"start_time": "2025-12-06T06:46:55.004441724Z",
"end_time": "2025-12-06T07:46:55.004442035Z",
"performance": {
"total_profit": 0.0028000000000000004,
"win_rate": 0.8333333333333334,
"max_drawdown": 0.0097,
"calmar_ratio": 109.56,
"sharpe_ratio": 8.41,
"sqn": 0.48,
"trades": 20,
"profit_factor": 1.28,
"expectancy": 0.28,
"total_days": 0,
"avg_trade_duration": 0,
"cagr": 0.2237,
"market_change": 0.0032,
"best_pair": "SOL/USDT",
"best_pair_profit": 0.0033,
"worst_pair": "TRB/USDT",
"worst_pair_profit": -0.0022
},
"full_hyperopt_event_id": "hkx4d4r8u4D1",
"parameters": {
"add_bb_lower_proximity": "0.944",
"add_position_callback": "0.067",
"add_position_decrease_ratio": "0.57",
"add_rsi_oversold_threshold": "33",
"add_stochrsi_oversold": "10",
"adjust_multiplier": "1.5",
"bb_length": "38",
"bb_lower_deviation": "0.937",
"bb_std": "5.89",
"bb_width_threshold": "0.026",
"exit_bb_upper_deviation": "0.938",
"exit_profit_tier1": "0.068",
"exit_profit_tier2": "0.161",
"exit_reduce_tier1": "0.67",
"exit_reduce_tier2": "0.55",
"exit_rsi_threshold": "62",
"exit_volume_multiplier": "6.6",
"h1_max_candles": "17",
"h1_max_consecutive_candles": "1",
"h1_rapid_rise_threshold": "0.207",
"max_entry_adjustments": "4",
"max_reduce_adjustments": "4",
"min_condition_count": "1",
"reduce_coefficient": "0.322",
"reduce_profit_base": "0.054",
"rsi_bull_threshold": "61",
"rsi_length": "14",
"rsi_oversold": "38",
"stochrsi_bull_threshold": "43",
"stochrsi_neutral_threshold": "33",
"volume_multiplier": "5.4"
},
"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.0028000000000000004,
"win_rate": 0.8333333333333334,
"max_drawdown": 0.0097,
"calmar_ratio": 109.56,
"sharpe_ratio": 8.41,
"sqn": 0.48,
"trades": 20,
"profit_factor": 1.28,
"expectancy": 0.28,
"total_days": 0,
"avg_trade_duration": 0,
"cagr": 0.2237,
"market_change": 0.0032,
"best_pair": "SOL/USDT",
"best_pair_profit": 0.0033,
"worst_pair": "TRB/USDT",
"worst_pair_profit": -0.0022
}