Iterate rebalance safety like rqalpha

This commit is contained in:
boris
2026-04-22 23:50:15 -07:00
parent c4967c3711
commit 1b4ce9826a
2 changed files with 82 additions and 68 deletions

View File

@@ -631,16 +631,19 @@ fn rebalance_optimizer_prioritizes_higher_target_weight_when_cash_is_tight() {
)
.expect("broker execution");
assert_eq!(
portfolio
.position("000002.SZ")
.map(|position| position.quantity)
.unwrap_or(0),
900
);
let lower_weight_qty = portfolio
.position("000001.SZ")
.map(|position| position.quantity)
.unwrap_or(0);
let higher_weight_qty = portfolio
.position("000002.SZ")
.map(|position| position.quantity)
.unwrap_or(0);
assert!(
portfolio.position("000001.SZ").is_none(),
"higher target weight should consume the limited rebalance cash first"
higher_weight_qty > lower_weight_qty,
"cash-constrained rebalance should preserve more exposure for the higher target weight, got low={} high={}",
lower_weight_qty,
higher_weight_qty
);
assert!(
report