diff --git a/static/index.html b/static/index.html index 1cfadec2..ca735faf 100644 --- a/static/index.html +++ b/static/index.html @@ -1959,9 +1959,55 @@ async function loadStrategyList() { } } +function sortBy(key) { + if (window._sortKey === key) { + window._sortDir = window._sortDir === 'desc' ? 'asc' : 'desc'; + } else { + window._sortKey = key; + window._sortDir = 'desc'; + } + renderStrategyTable(window._strats || []); +} + +function sortStrategies(strategies, key, dir) { + const get = (s) => { + const st = s.summary_stats || {}; const pf = st.portfolio || {}; + switch(key) { + case 'version': return s.version || ''; + case 'name': return s.name || ''; + case 'sizing_slots': return st.sizing_slots || 10; + case 'composite': return s._composite != null ? s._composite : -999; + case 'universality': return (st.universality || {}).score || 0; + case 'total_return': return pf.total_return_pct != null ? pf.total_return_pct : -999; + case 'capital_final': return pf.capital_final || 0; + case 'cagr': return pf.cagr_pct != null ? pf.cagr_pct : -999; + case 'trades': return st.total_trades || 0; + case 'hold': return st.avg_hold_days || 0; + case 'win_rate': return st.win_rate != null ? st.win_rate : -999; + case 'avg_profit': return st.avg_profit_pct != null ? st.avg_profit_pct : -999; + case 'sharpe': return st.sharpe_ratio != null ? st.sharpe_ratio : -999; + case 'profit_factor': return st.profit_factor != null ? st.profit_factor : -999; + case 'max_dd': return pf.portfolio_max_dd_pct != null ? pf.portfolio_max_dd_pct : 999; + default: return 0; + } + }; + const arr = [...strategies]; + arr.sort((a, b) => { + const va = get(a), vb = get(b); + let cmp = (typeof va === 'string') ? va.localeCompare(vb) : va - vb; + return dir === 'desc' ? -cmp : cmp; + }); + return arr; +} + function renderStrategyTable(strategies) { const el = document.getElementById('strategyList'); if (!strategies.length) { el.innerHTML = '
| 版本 | 名称 | ' + - '仓位 | ' + - '综合 | ' + - '普适 | ' + - '总收益 | ' + - '最终资产 | ' + - '年化 | ' + - '交易数 | ' + - '均持仓 | ' + - '胜率 | ' + - '平均收益 | 夏普 | ' + - '盈亏比 | 资产回撤 | ' + + th('version', '版本', 'text-left') + th('name', '名称', 'text-left') + + th('sizing_slots', '仓位', 'text-center') + + th('composite', '综合', 'text-right') + + th('universality', '普适', 'text-right') + + th('total_return', '总收益', 'text-right') + + th('capital_final', '最终资产', 'text-right') + + th('cagr', '年化', 'text-right') + + th('trades', '交易数', 'text-right') + + th('hold', '均持仓', 'text-right') + + th('win_rate', '胜率', 'text-right') + + th('avg_profit', '平均收益', 'text-right') + th('sharpe', '夏普', 'text-right') + + th('profit_factor', '盈亏比', 'text-right') + th('max_dd', '资产回撤', 'text-right') + '操作 |
|---|