feat(rotation): add position weight to detail JSON and viewer

- Record position_weights in daily_records during backtest run
- Export weight field per held asset in detail JSON
- Display weight percentage in backtest_viewer holdings cards
- Force-add backtest_viewer.html (previously ignored by *.html rule)
This commit is contained in:
2026-06-06 22:39:23 +08:00
parent 4973a9a2a5
commit eb3c82f05b
2 changed files with 718 additions and 0 deletions

View File

@@ -774,6 +774,7 @@ class SimpleRotationStrategy:
'removed': sorted(removed),
'factors': {k: round(v, 6) for k, v in factors.items()},
'threshold': threshold_val,
'position_weights': {k: round(v, 6) for k, v in self._position_weights.items()},
})
current_holdings = new_holdings
@@ -939,6 +940,7 @@ class SimpleRotationStrategy:
factors = record.get('factors', {})
holdings = set(record['holdings'])
threshold = record.get('threshold', 0.0)
position_weights = record.get('position_weights', {})
# Rank: sort all codes by momentum descending, rank 1 = highest
sorted_codes = sorted(factors.keys(), key=lambda c: factors[c], reverse=True)
@@ -995,6 +997,7 @@ class SimpleRotationStrategy:
'holding_days': holding_days,
'cum_return_etf': float(cum_ret_etf) if cum_ret_etf is not None else None,
'cum_return_idx': float(cum_ret_idx) if cum_ret_idx is not None else None,
'weight': float(position_weights.get(code, 0.0)) if is_held else None,
}
return assets