fix: rr_ratio统一用entry/stop/tp算(与promote同口径),不再用lifecycle的错值

This commit is contained in:
xxm
2026-08-18 12:33:10 +08:00
parent 236c7bce1a
commit b7535b9b24
+3 -8
View File
@@ -66,14 +66,8 @@ 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 bugstrategy_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
else:
# 用 entry/stop/tp 自己算(promote 同口径)
# 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)
@@ -82,6 +76,7 @@ def _build_full_analysis(code, entry, result):
_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:
# 无有效区间/止损/止盈时,用 holding 的旧 rr_ratio 或 0
rr = entry.get("rr_ratio", 0)
act = result.get("action", "")