feat: 研究Tab重构——策略子Tab按适应温区展开多行(每策略每温区一行+温区列+温区胜率/均盈/样本), 当前使用改为当前温区激活(regime_weights.active), 移除组合子Tab(温区动态激活替代固定组合方案), /api/research/strategies返回regime_winrates+regime_active
This commit is contained in:
@@ -540,9 +540,30 @@ def api_research_strategies():
|
||||
from strategy_lab import list_strategies, STRATEGY_DESCRIPTIONS
|
||||
pt = request.args.get('period_tag')
|
||||
strats = list_strategies(period_tag=pt)
|
||||
# 2026-08-13 温区自适应:为每个策略附加各温区表现(strategy_regime_perf)
|
||||
# + 当前温区激活状态(regime_weights)。前端按"适应温区"展开多行。
|
||||
_weights = _load_json(DATA_DIR / "strategy_weights.json", None) or {}
|
||||
_active_set = set(_weights.get("active") or [])
|
||||
_regime_winrates = {}
|
||||
try:
|
||||
import sqlite3 as _sq
|
||||
_c = _sq.connect(str(DATA_DIR / "mofin.db"), timeout=10)
|
||||
_c.execute("PRAGMA busy_timeout=10000")
|
||||
for _r in _c.execute(
|
||||
"SELECT strategy, regime, trades, win_rate, avg_pnl FROM strategy_regime_perf"
|
||||
).fetchall():
|
||||
_regime_winrates.setdefault(_r[0], {})[_r[1]] = {
|
||||
"trades": _r[2], "win_rate": _r[3], "avg_pnl": _r[4]
|
||||
}
|
||||
_c.close()
|
||||
except Exception:
|
||||
pass
|
||||
for s in strats:
|
||||
s['description'] = STRATEGY_DESCRIPTIONS.get(s['version'], {})
|
||||
return jsonify({'strategies': strats})
|
||||
s['regime_winrates'] = _regime_winrates.get(s['version'], {})
|
||||
# current = 当前温区激活(替代旧的 CURRENT_VERSIONS 硬编码)
|
||||
s['current'] = s['version'] in _active_set
|
||||
return jsonify({'strategies': strats, 'regime_active': sorted(_active_set)})
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
Reference in New Issue
Block a user