From b7535b9b245a14a4ff7a806c3e8c79800e8bb899 Mon Sep 17 00:00:00 2001 From: xxm Date: Tue, 18 Aug 2026 12:33:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20rr=5Fratio=E7=BB=9F=E4=B8=80=E7=94=A8ent?= =?UTF-8?q?ry/stop/tp=E7=AE=97(=E4=B8=8Epromote=E5=90=8C=E5=8F=A3=E5=BE=84?= =?UTF-8?q?),=E4=B8=8D=E5=86=8D=E7=94=A8lifecycle=E7=9A=84=E9=94=99?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/per_stock_reassess.py | 27 ++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/deploy/profile-scripts/per_stock_reassess.py b/deploy/profile-scripts/per_stock_reassess.py index 6a1480b5..0ebaed0e 100644 --- a/deploy/profile-scripts/per_stock_reassess.py +++ b/deploy/profile-scripts/per_stock_reassess.py @@ -66,23 +66,18 @@ def _build_full_analysis(code, entry, result): eh = result.get("entry_high") sl = result.get("stop_loss") or entry.get("stop_loss", 0) tp = result.get("take_profit") or entry.get("take_profit", 0) - # 2026-08-18 修复 rr_ratio=0 bug:strategy_lifecycle 的 rr_ratio 可能为 0, - # 用 entry/stop/tp 自己算(RR = (tp-mid)/(mid-sl),mid=(el+eh)/2) - # 若 strategy_lifecycle 给了 rr_ratio > 0 用它;否则用 entry/stop/tp 算 - _rr_from_lifecycle = result.get("rr_ratio") or 0 - if _rr_from_lifecycle > 0: - rr = _rr_from_lifecycle + # 2026-08-18 修复 rr_ratio:统一用 entry/stop/tp 算(与 promote 同口径 rr = (tp-mid)/(mid-sl)) + # strategy_lifecycle 的 rr_ratio 可能算错(6.5 vs 实际 8.64),统一用 entry/stop/tp 算最准 + _el_rr = result.get("entry_low") if result.get("entry_low") is not None else entry.get("entry_low", 0) + _eh_rr = result.get("entry_high") if result.get("entry_high") is not None else entry.get("entry_high", 0) + _sl_rr = result.get("stop_loss") or entry.get("stop_loss", 0) + _tp_rr = result.get("take_profit") or entry.get("take_profit", 0) + if _el_rr > 0 and _eh_rr > _el_rr and _sl_rr > 0 and _tp_rr > 0: + _mid_rr = (_el_rr + _eh_rr) / 2 + rr = round((_tp_rr - _mid_rr) / (_mid_rr - _sl_rr), 2) if _mid_rr > _sl_rr else 0 else: - # 用 entry/stop/tp 自己算(promote 同口径) - _el_rr = result.get("entry_low") if result.get("entry_low") is not None else entry.get("entry_low", 0) - _eh_rr = result.get("entry_high") if result.get("entry_high") is not None else entry.get("entry_high", 0) - _sl_rr = result.get("stop_loss") or entry.get("stop_loss", 0) - _tp_rr = result.get("take_profit") or entry.get("take_profit", 0) - if _el_rr > 0 and _eh_rr > _el_rr and _sl_rr > 0 and _tp_rr > 0: - _mid_rr = (_el_rr + _eh_rr) / 2 - rr = round((_tp_rr - _mid_rr) / (_mid_rr - _sl_rr), 2) if _mid_rr > _sl_rr else 0 - else: - rr = entry.get("rr_ratio", 0) + # 无有效区间/止损/止盈时,用 holding 的旧 rr_ratio 或 0 + rr = entry.get("rr_ratio", 0) act = result.get("action", "") # ── 从DB拉取大盘、基本面、资金流 ──