修复AiQuant策略表达式回测执行语义

This commit is contained in:
boris
2026-06-15 11:16:04 +08:00
parent d3d08276ae
commit 1c31fa80d2
8 changed files with 1227 additions and 292 deletions
+14 -5
View File
@@ -97,7 +97,7 @@ impl DynamicSlippageConfig {
}
}
fn ratio(
pub(crate) fn ratio(
&self,
snapshot: &crate::data::DailyMarketSnapshot,
raw_price: f64,
@@ -4706,8 +4706,12 @@ where
let quote_quantity_limited =
self.quote_quantity_limited_for_window(matching_type, start_cursor, end_cursor);
let lot = round_lot.max(1);
let use_decision_time_quote =
matching_type == MatchingType::NextTickLast && start_cursor.is_some();
let exact_time_order_quote = matching_type != MatchingType::NextTickLast
&& start_cursor.is_some()
&& end_cursor.is_some()
&& start_cursor == end_cursor;
let use_decision_time_quote = start_cursor.is_some()
&& (matching_type == MatchingType::NextTickLast || exact_time_order_quote);
let eligible_quotes: Vec<&IntradayExecutionQuote> = if use_decision_time_quote {
self.latest_known_quote_at_or_before(
quotes,
@@ -5428,7 +5432,7 @@ mod tests {
);
let default_rule = default_broker.buy_rule_check(date, &snapshot, &candidate, None);
assert!(!default_rule.allowed);
assert_eq!(default_rule.reason.as_deref(), Some("trade_disabled"));
assert_eq!(default_rule.reason.as_deref(), Some("buy_disabled"));
let aiquant_broker = BrokerSimulator::new_with_execution_price(
ChinaAShareCostModel::default(),
@@ -5438,12 +5442,17 @@ mod tests {
.with_aiquant_rqalpha_execution_rules(true);
let aiquant_rule = aiquant_broker.buy_rule_check(date, &snapshot, &candidate, None);
assert!(!aiquant_rule.allowed);
assert_eq!(aiquant_rule.reason.as_deref(), Some("trade_disabled"));
assert_eq!(aiquant_rule.reason.as_deref(), Some("buy_disabled"));
let tradable_candidate = limit_test_candidate(true, true);
let aiquant_rule =
aiquant_broker.buy_rule_check(date, &snapshot, &tradable_candidate, None);
assert!(aiquant_rule.allowed);
let lower_limit_buyable_candidate = limit_test_candidate(true, false);
let aiquant_rule =
aiquant_broker.buy_rule_check(date, &snapshot, &lower_limit_buyable_candidate, None);
assert!(aiquant_rule.allowed);
}
#[test]