From f09676bae1896a8ba3c0d3363b35e8be2de3c8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Wed, 8 Jul 2026 13:55:14 +0800 Subject: [PATCH] 1 --- config/my_batch_volatility_pullback.json | 21 ---- config/my_batch_vp_more_opportunities.json | 122 +++++++++++++++++++++ scripts/apply_vp_more_opportunities.sh | 17 +++ trading_system/config.py | 1 + trading_system/volatility_pullback.py | 30 ++++- 5 files changed, 164 insertions(+), 27 deletions(-) create mode 100644 config/my_batch_vp_more_opportunities.json create mode 100755 scripts/apply_vp_more_opportunities.sh diff --git a/config/my_batch_volatility_pullback.json b/config/my_batch_volatility_pullback.json index 64779a1..2ec73f7 100644 --- a/config/my_batch_volatility_pullback.json +++ b/config/my_batch_volatility_pullback.json @@ -143,27 +143,6 @@ "category": "strategy", "description": "瞬时波动观察周期" }, - { - "key": "VP_VOL_LOOKBACK_BARS", - "value": 5, - "type": "number", - "category": "strategy", - "description": "15m波动计算根数" - }, - { - "key": "VP_LONG_MIN_DROP_PCT", - "value": 0.008, - "type": "number", - "category": "strategy", - "description": "做多:15m合计跌幅≥0.8%" - }, - { - "key": "VP_SHORT_MIN_RISE_PCT", - "value": 0.008, - "type": "number", - "category": "strategy", - "description": "做空:15m合计涨幅≥0.8%" - }, { "key": "VP_SIGNAL_STRENGTH", "value": 8, diff --git a/config/my_batch_vp_more_opportunities.json b/config/my_batch_vp_more_opportunities.json new file mode 100644 index 0000000..4b41f19 --- /dev/null +++ b/config/my_batch_vp_more_opportunities.json @@ -0,0 +1,122 @@ +[ + { + "key": "VP_ALLOW_4H_NEUTRAL", + "value": true, + "type": "boolean", + "category": "strategy", + "description": "增机会:4H中性时按1H方向+波动触发" + }, + { + "key": "VP_1H_FLUSH_MIN_PCT", + "value": 0.003, + "type": "number", + "category": "strategy", + "description": "1H进行中波动门槛 0.5%→0.3%" + }, + { + "key": "VP_NEAR_PRIOR_LOW_PCT", + "value": 0.012, + "type": "number", + "category": "strategy", + "description": "入场区放宽:前低上方1.2%内" + }, + { + "key": "VP_MAX_BELOW_PRIOR_LOW_PCT", + "value": 0.006, + "type": "number", + "category": "strategy", + "description": "允许刺破前低0.6%" + }, + { + "key": "VP_NEAR_PRIOR_HIGH_PCT", + "value": 0.012, + "type": "number", + "category": "strategy" + }, + { + "key": "VP_MAX_ABOVE_PRIOR_HIGH_PCT", + "value": 0.006, + "type": "number", + "category": "strategy" + }, + { + "key": "VP_LONG_MIN_DROP_PCT", + "value": 0.004, + "type": "number", + "category": "strategy", + "description": "15m辅助触发 0.6%→0.4%" + }, + { + "key": "VP_SHORT_MIN_RISE_PCT", + "value": 0.004, + "type": "number", + "category": "strategy" + }, + { + "key": "VP_VOL_LOOKBACK_BARS", + "value": 3, + "type": "number", + "category": "strategy" + }, + { + "key": "VP_PRIOR_STRUCTURE_BARS", + "value": 18, + "type": "number", + "category": "strategy", + "description": "结构位回看略放宽" + }, + { + "key": "VP_SCAN_INTERVAL_SEC", + "value": 120, + "type": "number", + "category": "scan", + "description": "扫描 3min→2min" + }, + { + "key": "SCAN_INTERVAL", + "value": 120, + "type": "number", + "category": "scan" + }, + { + "key": "BETA_FILTER_THRESHOLD", + "value": -0.012, + "type": "number", + "category": "strategy", + "description": "大盘禁多略放宽:15m/1h跌1.2%才拦" + }, + { + "key": "ENTRY_SYMBOL_COOLDOWN_SEC", + "value": 600, + "type": "number", + "category": "strategy", + "description": "同币冷却 20min→10min" + }, + { + "key": "MAX_OPEN_POSITIONS", + "value": 3, + "type": "number", + "category": "risk" + }, + { + "key": "TOP_N_SYMBOLS", + "value": 12, + "type": "number", + "category": "scan", + "description": "每轮多扫几个候选" + }, + { + "key": "MIN_CHANGE_PERCENT", + "value": 0.8, + "type": "number", + "category": "scan", + "description": "前置涨跌幅 1%→0.8%" + }, + { + "key": "MANUAL_REDUCED_SYMBOL_SIGNAL_BOOST", + "value": 0, + "type": "number", + "category": "strategy", + "description": "山寨不再额外+1信号门槛" + } +] diff --git a/scripts/apply_vp_more_opportunities.sh b/scripts/apply_vp_more_opportunities.sh new file mode 100755 index 0000000..afa4bc9 --- /dev/null +++ b/scripts/apply_vp_more_opportunities.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# VP 增机会档:放宽波动/结构/扫描门槛(在已启用 VP 基础上叠加) +# 用法: ./scripts/apply_vp_more_opportunities.sh [--dry-run] +set -euo pipefail +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +cd "$ROOT" +PYTHON_BIN="" +for _py in "${ROOT}/.venv/bin/python" "${ROOT}/trading_system/.venv/bin/python" "${ROOT}/backend/.venv/bin/python"; do + [ -x "$_py" ] && PYTHON_BIN="$_py" && break +done +PYTHON_BIN="${PYTHON_BIN:-$(command -v python3)}" +DRY_RUN=() +[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=(--dry-run) +exec "$PYTHON_BIN" "$ROOT/scripts/apply_config_patch_only.py" \ + --from "$ROOT/config/my_batch_vp_more_opportunities.json" \ + --updated-by "vp_more_opportunities" \ + "${DRY_RUN[@]}" diff --git a/trading_system/config.py b/trading_system/config.py index 6144a4c..a89bb17 100644 --- a/trading_system/config.py +++ b/trading_system/config.py @@ -424,6 +424,7 @@ DEFAULT_TRADING_CONFIG = { 'VP_NEAR_PRIOR_HIGH_PCT': 0.008, 'VP_MAX_ABOVE_PRIOR_HIGH_PCT': 0.004, 'VP_SCAN_INTERVAL_SEC': 180, + 'VP_ALLOW_4H_NEUTRAL': False, # ===== 智能入场(方案C)===== # 根治方案:默认关闭。关闭后回归“纯限价单模式”(不追价/不市价兜底/未成交撤单跳过) diff --git a/trading_system/volatility_pullback.py b/trading_system/volatility_pullback.py index 3924110..ce61a7b 100644 --- a/trading_system/volatility_pullback.py +++ b/trading_system/volatility_pullback.py @@ -212,9 +212,22 @@ async def _evaluate_instant_flush( ) -> Dict[str, Any]: """1H 进行中 K 线快速波动 + 前结构低/高点入场(更贴近手动抄底/摸顶)。""" t4 = (trend_4h or "neutral").strip().lower() - if t4 not in ("up", "down"): - return _fail(f"4H 趋势未明确(4H={t4}),即时模式需 up/down", trend_4h) - direction = "BUY" if t4 == "up" else "SELL" + trend_1h = judge_trend_1h( + price_f, symbol_info.get("ema20"), symbol_info.get("ema50") + ) + t1 = trend_1h + allow_neutral_4h = bool(_cfg("VP_ALLOW_4H_NEUTRAL", False)) + + if t4 in ("up", "down"): + direction = "BUY" if t4 == "up" else "SELL" + elif allow_neutral_4h and t1 in ("up", "down"): + direction = "BUY" if t1 == "up" else "SELL" + else: + return _fail( + f"4H 趋势未明确(4H={t4})" + + (f",1H={t1}" if allow_neutral_4h else ",即时模式需 up/down"), + trend_4h, + ) lookback = max(8, int(_cfg("VP_RANGE_LOOKBACK_BARS", 24) or 24)) prior_bars = max(3, int(_cfg("VP_PRIOR_STRUCTURE_BARS", 12) or 12)) @@ -243,7 +256,6 @@ async def _evaluate_instant_flush( short_min_rise = float(_cfg("VP_SHORT_MIN_RISE_PCT", 0.006) or 0.006) vol_change = await _period_change(client, symbol, vol_iv, vol_bars) - trend_1h = judge_trend_1h(price_f, symbol_info.get("ema20"), symbol_info.get("ema50")) reasons: List[str] = [] if direction == "BUY": @@ -275,7 +287,10 @@ async def _evaluate_instant_flush( if vol_ok: reasons.append(f"{vol_iv}跌{(vol_change or 0)*100:.2f}%") reasons.append(f"贴近前低{prior_low:.6f}") - reasons.append(f"4H向上") + if t4 == "up": + reasons.append("4H向上") + else: + reasons.append(f"4H中性+1H向上") struct_key, struct_val = "prior_structure_low", prior_low else: flush_ok = flush["flush_up_pct"] >= flush_min @@ -299,7 +314,10 @@ async def _evaluate_instant_flush( if vol_ok: reasons.append(f"{vol_iv}涨{(vol_change or 0)*100:.2f}%") reasons.append(f"贴近前高{prior_high:.6f}") - reasons.append(f"4H向下") + if t4 == "down": + reasons.append("4H向下") + else: + reasons.append(f"4H中性+1H向下") struct_key, struct_val = "prior_structure_high", prior_high strength = int(_cfg("VP_SIGNAL_STRENGTH", 8) or 8)