修正周期调仓等权资金预算

This commit is contained in:
boris
2026-07-12 01:45:33 +08:00
parent 57345e8230
commit c094e78bef
+24 -12
View File
@@ -9397,12 +9397,8 @@ impl Strategy for PlatformExprStrategy {
projected.cash() projected.cash()
} }
}; };
let fixed_buy_cash = if self.config.aiquant_transaction_cost {
aiquant_available_cash * trading_ratio / selection_limit as f64
} else {
aiquant_total_value * trading_ratio / selection_limit as f64
};
let target_budget = aiquant_total_value * trading_ratio; let target_budget = aiquant_total_value * trading_ratio;
let fixed_buy_cash = target_budget / selection_limit as f64;
let mut rebalance_working_symbols = slot_working_symbols.clone(); let mut rebalance_working_symbols = slot_working_symbols.clone();
if self.config.release_slot_on_exit_signal { if self.config.release_slot_on_exit_signal {
for symbol in &same_day_sold_symbols { for symbol in &same_day_sold_symbols {
@@ -25285,7 +25281,7 @@ mod tests {
} }
#[test] #[test]
fn platform_aiquant_periodic_rebalance_uses_cash_divided_by_top_n_buy_budget() { fn platform_aiquant_periodic_rebalance_uses_total_equity_equal_weight_buy_budget() {
let prev_date = d(2025, 5, 13); let prev_date = d(2025, 5, 13);
let date = d(2025, 5, 14); let date = d(2025, 5, 14);
let retained_symbols = (1..=17) let retained_symbols = (1..=17)
@@ -25484,12 +25480,28 @@ mod tests {
"{:?}", "{:?}",
decision.order_intents decision.order_intents
); );
let periodic_buy_values = decision
.order_intents
.iter()
.filter_map(|intent| match intent {
OrderIntent::Value { value, reason, .. }
if reason == "periodic_rebalance_buy" => Some(*value),
_ => None,
})
.collect::<Vec<_>>();
let equal_weight_target = 5_060_000.0 / 40.0;
assert!( assert!(
decision.order_intents.iter().all(|intent| match intent { periodic_buy_values
OrderIntent::Value { value, reason, .. } if reason == "periodic_rebalance_buy" => .iter()
(*value - 75_444.8).abs() < 1e-6, .take(periodic_buy_values.len().saturating_sub(1))
_ => true, .all(|value| (*value - equal_weight_target).abs() < 1e-6),
}), "{:?}",
decision.order_intents
);
assert!(
periodic_buy_values
.last()
.is_some_and(|value| *value > 0.0 && *value <= equal_weight_target),
"{:?}", "{:?}",
decision.order_intents decision.order_intents
); );
@@ -25646,7 +25658,7 @@ mod tests {
reason, reason,
} if symbol == "000002.SZ" } if symbol == "000002.SZ"
&& reason == "periodic_rebalance_buy" && reason == "periodic_rebalance_buy"
&& (*value - 5_000.0).abs() < 1e-6 && (*value - 10_000.0).abs() < 1e-6
)), )),
"{:?}", "{:?}",
decision.order_intents decision.order_intents