From 8d8fd711493805ef0c1f419cb3f38c04a1149d67 Mon Sep 17 00:00:00 2001 From: aszerW Date: Sat, 6 Jun 2026 22:48:40 +0800 Subject: [PATCH] feat(viewer): sort holdings cards by position weight descending Display largest position first in the holdings panel for better readability --- rotation/backtest_viewer.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rotation/backtest_viewer.html b/rotation/backtest_viewer.html index 38b106d..a7a77e3 100644 --- a/rotation/backtest_viewer.html +++ b/rotation/backtest_viewer.html @@ -403,7 +403,13 @@ function renderHoldings(day, meta) { } let html = ''; - for (const code of day.holdings) { + // Sort holdings by weight descending (largest position first) + const sortedHoldings = [...day.holdings].sort((a, b) => { + const wa = day.assets[a] && day.assets[a].weight !== null ? day.assets[a].weight : 0; + const wb = day.assets[b] && day.assets[b].weight !== null ? day.assets[b].weight : 0; + return wb - wa; + }); + for (const code of sortedHoldings) { const a = day.assets[code]; if (!a) continue; const info = meta.codes[code] || {};