Iterate rebalance safety like rqalpha
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user