From c0a4bb0c1f56817c990d1494adaf92da4d932b56 Mon Sep 17 00:00:00 2001 From: hmo Date: Wed, 29 Jul 2026 03:52:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8D=A2=E4=BB=93=E5=A5=97=E5=8F=96?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E5=8D=87=E7=BA=A7=E4=B8=BAv7.1=E5=9B=A0?= =?UTF-8?q?=E5=AD=90=E8=AF=84=E5=88=86=E5=8D=87=E5=BA=8F=E2=80=94=E2=80=94?= =?UTF-8?q?=E6=96=B0=E4=BF=A1=E5=8F=B7=E8=B6=85=E7=8E=B0=E9=87=91=E9=A2=84?= =?UTF-8?q?=E7=AE=97=E6=97=B6=EF=BC=8C=E4=BB=8E=E5=9B=A0=E5=AD=90=E8=AF=84?= =?UTF-8?q?=E5=88=86=E6=9C=80=E4=BD=8E=E7=9A=84=E6=8C=81=E4=BB=93=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E5=A5=97=E5=8F=96(=E5=AE=9E=E6=B5=8B:=E5=BD=B1?= =?UTF-8?q?=E7=9F=B320=E5=88=86/=E6=B5=B7=E5=8D=9A25=E5=88=86/=E5=8D=8E?= =?UTF-8?q?=E6=81=9227=E5=88=86=E4=BC=98=E5=85=88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/profile-scripts/mofin_db.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/deploy/profile-scripts/mofin_db.py b/deploy/profile-scripts/mofin_db.py index 42c7cb6a..88fb8820 100644 --- a/deploy/profile-scripts/mofin_db.py +++ b/deploy/profile-scripts/mofin_db.py @@ -1809,9 +1809,34 @@ def flush_rec_digest(max_items=5): LEFT JOIN live_prices lp ON hs.code = lp.code WHERE hs.status='active' AND h.shares > 0 AND hs.timing_signal IN ('弱势持有','观望','持有') - ORDER BY CASE hs.timing_signal WHEN '弱势持有' THEN 0 WHEN '观望' THEN 1 ELSE 2 END, - h.position_pct DESC """).fetchall() + # ── v7.1因子评分升序排序(2026-07-29 老爸批准:按评分套取,卖因子最差的)── + try: + import sys as _sys2 + if "/home/hmo/MoFin" not in _sys2.path: + _sys2.path.insert(0, "/home/hmo/MoFin") + from backtest_framework import prepare_bars as _pb, compute_single_score as _cs + from datetime import datetime as _dt2, timedelta as _td2 + _end2 = _dt2.now().strftime('%Y-%m-%d') + _start2 = (_dt2.now() - _td2(days=150)).strftime('%Y-%m-%d') + _scored = [] + for w in weak: + _sc = 0 + try: + _bars = _pb(w['code'], _start2, _end2) + if _bars and len(_bars) >= 25: + _r = _cs(_bars) + _sc = _r[0] if _r else 0 + except Exception: + pass + _scored.append((_sc, w)) + _scored.sort(key=lambda x: x[0]) # 评分最低 = 优先套取 + weak = [w for _, w in _scored] + print(" [换仓] 因子评分排序: " + ", ".join(f"{w['name']}({s})" for s, w in _scored[:5]), flush=True) + except Exception as _se: + print(f" [换仓] 评分排序失败(回退信号排序): {_se}", flush=True) + weak = sorted(weak, key=lambda w: ({'弱势持有': 0, '观望': 1}.get(w['timing_signal'], 2), + -(w['position_pct'] or 0))) if weak: need_pct = queued[0][1] plan = []