fix(position): 仓位模糊时系统按RR公式自动计算,不丢弃

- 老爸: 不明确就让它变得明确,不是丢弃
- 公式: RR1.5-3=>8%,3-5=>12%,5+=>15% ×成长系数0.85,钳位5-20%
- 写入标记(系统按RRx.x自动计算,见原建议仓位)
This commit is contained in:
hmo
2026-07-27 11:00:39 +08:00
parent f3de4fb7fc
commit 727467f1af
+27
View File
@@ -1259,6 +1259,33 @@ def sync_recommend_tag(conn, code: str, timing_signal: str):
_h = conn.execute("SELECT shares FROM holdings WHERE code=? AND is_active=1", (code,)).fetchone()
if not (_h and (_h[0] or 0) > 0):
timing_signal = "" # 非持仓的卖出/止盈不算动作信号
# ── 仓位自动补全(2026-07-27 老爸:不明确就让它明确,不是丢弃)──
# LLM 经常输出"减仓或观望/中等仓位"等模糊表述,系统按公式自动计算。
# 基础仓位 by RR(<1.5→不推荐,1.5~3→8%,3~5→12%,5+→15%) × 成长系数0.85(兜底)
# → 最终范围5-20%
if timing_signal in _ACTION_BUY:
import re as _re2
_pos_r = conn.execute(
"SELECT rr_ratio, position_advice FROM holding_strategies WHERE code=? AND status='active'", (code,)).fetchone()
if _pos_r and not _re2.search(r'\d+(?:\.\d+)?\s*%', _pos_r[1] or ''):
_rr_pos = float(_pos_r[0] or 0)
if _rr_pos < 1.5:
_pct = 0 # RR不推荐
elif _rr_pos < 3:
_pct = 8
elif _rr_pos < 5:
_pct = 12
else:
_pct = 15
# 系数兜底:成长股0.85(最保守),大盘系数1.0(中性)
_pct = round(_pct * 0.85, 0)
_pct = max(5, min(20, _pct))
_pos_auto = f"{int(_pct)}%(系统按RR{_rr_pos:.1f}自动计算,见原建议仓位)"
conn.execute(
"UPDATE holding_strategies SET position_advice=? WHERE code=? AND status='active'",
(_pos_auto, code))
conn.commit()
print(f" [AUTO-POS] {code} 仓位'{_pos_r[1]}''{_pos_auto}'", flush=True)
if timing_signal in _ACTION_BUY or timing_signal in _ACTION_SELL:
conn.execute(
"UPDATE holding_strategies SET tag='current_recommend' "