diff --git a/strategy_lab.py b/strategy_lab.py index 02a2db49..5ca4ec37 100644 --- a/strategy_lab.py +++ b/strategy_lab.py @@ -84,7 +84,7 @@ STRATEGIES = { "dist_ma20_min": 4, "vol_ratio_min": 1.2, "vol_ratio_max": 1.5, "ma20_slope_max": 1.5, - "mkt_above_ma20": True, "mkt_slope_max": -0.05, + "mkt_above_ma20": True, "mkt_slope_max": -0.05, "mkt_adx_min": 20, "hh_only": True}}, "exit": {"tp_pct": 0.15, "sl_atr": 1.5, "max_hold_days": 20}, "sizing": {"kelly": True, "kelly_fraction": 0.5}, @@ -380,6 +380,7 @@ def _load_index_ctx(index_code, start_date, end_date): 'above_ma20': (b.get('close') or 0) > ma20 if ma20 > 0 else None, 'ma20_slope': slope, 'roc': b.get('roc'), + 'adx': b.get('adx'), # 趋势强度(choppy市<20,趋势市>25,2026-07-30强化趋势过滤) } return ctx @@ -594,6 +595,7 @@ def pass_filters(factors, filters): # 大盘 if filters.get('mkt_above_ma20') and factors.get('mkt_above_ma20') is not True: return False if not chk('mkt_slope', filters.get('mkt_slope_min'), filters.get('mkt_slope_max')): return False + if not chk('mkt_adx', filters.get('mkt_adx_min'), filters.get('mkt_adx_max')): return False # 行业 if not chk('sector_change', filters.get('sector_change_min'), filters.get('sector_change_max')): return False if not chk('sector_rank_pct', None, filters.get('sector_rank_pct_max')): return False @@ -741,6 +743,7 @@ def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=T factors['mkt_above_ma20'] = mk.get('above_ma20') factors['mkt_slope'] = mk.get('ma20_slope') factors['mkt_roc'] = mk.get('roc') + factors['mkt_adx'] = mk.get('adx') factors['sector_change'] = sc_ctx.get('change') factors['sector_rank_pct'] = sc_ctx.get('rank_pct') factors['sector_inflow'] = sc_ctx.get('inflow')