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] || {};