diff --git a/deploy/profile-scripts/mofin_db.py b/deploy/profile-scripts/mofin_db.py index 88fb8820..42c7cb6a 100644 --- a/deploy/profile-scripts/mofin_db.py +++ b/deploy/profile-scripts/mofin_db.py @@ -1809,34 +1809,9 @@ 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 = []