修复AiQuant调仓现金可用语义
This commit is contained in:
@@ -7160,7 +7160,7 @@ impl Strategy for PlatformExprStrategy {
|
||||
slot_working_symbols.remove(symbol);
|
||||
}
|
||||
|
||||
if !self.config.aiquant_transaction_cost || !same_day_sold_symbols.is_empty() {
|
||||
if !self.config.aiquant_transaction_cost {
|
||||
aiquant_available_cash = projected.cash();
|
||||
}
|
||||
let fixed_buy_cash = aiquant_total_value * trading_ratio / selection_limit as f64;
|
||||
@@ -16736,6 +16736,7 @@ mod tests {
|
||||
cfg.stop_loss_expr.clear();
|
||||
cfg.daily_top_up_enabled = true;
|
||||
cfg.intraday_execution_time = Some(NaiveTime::from_hms_opt(9, 33, 0).unwrap());
|
||||
let base_cfg = cfg.clone();
|
||||
let mut strategy = PlatformExprStrategy::new(cfg);
|
||||
strategy.rebalance_day_counter = 20;
|
||||
|
||||
@@ -16772,6 +16773,51 @@ mod tests {
|
||||
"{:?}",
|
||||
decision.order_intents
|
||||
);
|
||||
|
||||
let mut aiquant_portfolio = PortfolioState::new(4_000.0);
|
||||
aiquant_portfolio
|
||||
.position_mut("000003.SZ")
|
||||
.buy(prev_date, 1_000, 10.0);
|
||||
let aiquant_ctx = StrategyContext {
|
||||
execution_date: date,
|
||||
decision_date: date,
|
||||
decision_index: 20,
|
||||
data: &data,
|
||||
portfolio: &aiquant_portfolio,
|
||||
futures_account: None,
|
||||
open_orders: &[],
|
||||
dynamic_universe: None,
|
||||
subscriptions: &subscriptions,
|
||||
process_events: &[],
|
||||
active_process_event: None,
|
||||
active_datetime: None,
|
||||
order_events: &[],
|
||||
fills: &[],
|
||||
};
|
||||
let mut aiquant_cfg = base_cfg;
|
||||
aiquant_cfg.aiquant_transaction_cost = true;
|
||||
let mut aiquant_strategy = PlatformExprStrategy::new(aiquant_cfg);
|
||||
aiquant_strategy.rebalance_day_counter = 20;
|
||||
|
||||
let aiquant_decision = aiquant_strategy
|
||||
.on_day(&aiquant_ctx)
|
||||
.expect("aiquant platform decision");
|
||||
let aiquant_periodic_buys = aiquant_decision
|
||||
.order_intents
|
||||
.iter()
|
||||
.filter(|intent| {
|
||||
matches!(
|
||||
intent,
|
||||
OrderIntent::Value { reason, .. } if reason == "periodic_rebalance_buy"
|
||||
)
|
||||
})
|
||||
.count();
|
||||
|
||||
assert_eq!(
|
||||
aiquant_periodic_buys, 1,
|
||||
"{:?}",
|
||||
aiquant_decision.order_intents
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user