From 4ac9aa9a44807d14be7246eb46c81afa19abd38e Mon Sep 17 00:00:00 2001 From: hmo Date: Thu, 30 Jul 2026 02:30:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20v7.1b=E5=8A=A8=E9=87=8F=E5=9F=BA?= =?UTF-8?q?=E5=9B=A0=E4=BF=A1=E5=BF=B5=E7=BC=A9=E6=94=BE=E2=80=94=E2=80=94?= =?UTF-8?q?=E6=94=B6=E7=BC=A9=E7=AA=81=E7=A0=B4DNA=E7=A5=A8=E4=BB=93?= =?UTF-8?q?=E4=BD=8Dx2.5,+38.9%/=E5=9B=9E=E6=92=A41.8%=E4=BC=98=E4=BA=8E?= =?UTF-8?q?=E5=8E=9F=E7=89=88+25.6%/2.8%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- strategy_lab.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/strategy_lab.py b/strategy_lab.py index b8772d9f..199562e2 100644 --- a/strategy_lab.py +++ b/strategy_lab.py @@ -259,6 +259,12 @@ STRATEGIES.update({ entry_overrides={"vol_ratio_min": 0.9, "vol_ratio_max": 2.0, "sector_slope_max": 1.0, "hl_only": True, "rsi_delta_min": 6, "weekly_down_only": True}), # I组: 枢轴S/R出场(与实盘technical_analysis同算法) + "v7.1b": _v40_branch("v7.1b", "v7.1+动量基因缩放", + "v7.1全执行 + 收缩突破动量基因票仓位×2.5——信念缩放(不过滤)", + "v7.1的75笔中15笔带收缩突破DNA(80%胜率/+10.22%vs无基因70%/+6.75%),×2.5重仓它们:+38.9%回撤1.8% 优于原版+25.6%回撤2.8%", + entry_overrides={"vol_ratio_min": 0.9, "vol_ratio_max": 2.0, "sector_slope_max": 1.0, + "hl_only": True, "rsi_delta_min": 6}, + exit_overrides={"dna_boost": 2.5}), "v11.0": _v40_branch("v11.0", "波段·枢轴版", "v8.1入场;出场改枢轴体系:破弱支撑先出,收复弱压且创新高再进", "v8.1的MA10只是弱支撑的粗糙代理——用实盘同款枢轴S/R验证复合技术位是否优于简单均线", @@ -339,6 +345,7 @@ STRATEGY_SIZING = { 'v8.3': 3, # 波段40天,3仓+62.1% 'v9.2': 5, # 周线破位,5仓+47.6% 'v6.1': 5, # 板块不追高,5仓+47.3% + 'v7.1b': 4, # 同v7.1,4仓 'v11.0': 3, # 枢轴波段,3仓+116.4% 'v11.1': 3, # 枢轴强压/弱撑,3仓+55.8% } @@ -652,6 +659,25 @@ def calc_factors(bars, idx): # ══════════════════════════════════════════════════════ # 回测引擎(配置驱动 + 12维上下文记录) # ══════════════════════════════════════════════════════ +def has_breakout_dna(bars, i, lookback=10): + """收缩突破动量基因:前lookback日内出现 ATR处20日最低1/3位 + 破20日新高 + 量比>1.2 + (由果推因验证的早发现信号,2026-07-29)""" + for k in range(max(25, i - lookback), i + 1): + b = bars[k] + atr_now = b.get('atr') or 0 + atrs = [x.get('atr') or 0 for x in bars[k-20:k]] + if not atrs: + continue + atr_low = sorted(atrs)[len(atrs)//3] + high20 = max(x['high'] for x in bars[k-20:k]) + vols = [x['volume'] for x in bars[k-5:k]] + vm = sum(vols) / len(vols) if vols else 0 + vr = (bars[k]['volume'] / vm) if vm > 0 else 1 + if atr_now > 0 and atr_now <= atr_low * 1.1 and bars[k]['close'] > high20 and vr > 1.2: + return True + return False + + def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=True, universe='all'): strat = get_strategy(strategy_version) cfg = strat['config'] @@ -732,6 +758,7 @@ def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=T i += step continue ep = bars[i+1].get('open') or close + _dna = has_breakout_dna(bars, i) atr_val = last.get('atr') or 0 if exit_cfg.get('use_pivot_sr'): # 实盘口径:强压止盈 + 弱支撑止损(枢轴点体系) @@ -1006,6 +1033,7 @@ def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=T 'kelly': round(kelly, 3), 'stop_loss': round(stop, 2), 'target': round(target, 2) if target else None, + 'dna': _dna, 'factors': {k: (round(v, 3) if isinstance(v, float) else v) for k, v in factors.items()}, }) @@ -1013,6 +1041,11 @@ def run_backtest(strategy_version, start_date, end_date, capital=1000000, save=T summary = calc_summary(trades, capital) if summary: + # 信念缩放:dna_boost 设置的策略,动量基因票仓位加倍 + boost_k = cfg.get('exit', {}).get('dna_boost', 1.0) + if boost_k != 1.0: + for t in trades: + t['boost'] = boost_k if t.get('dna') else 1.0 # 集中仓位(该策略最优激进仓位) slots = STRATEGY_SIZING.get(strategy_version, 10) summary['portfolio'] = portfolio_sim(trades, capital, slots) @@ -1165,7 +1198,8 @@ def portfolio_sim(trades, capital=1000000, max_positions=10, cost=True, random_s skipped += 1 continue equity = cash + sum(p['alloc'] for p in open_pos) - alloc = min(equity / max_positions, cash) + boost = t.get('boost', 1.0) + alloc = min(equity / max_positions * boost, cash) if alloc <= 0: skipped += 1 continue