修正执行价quote多时间加载

This commit is contained in:
boris
2026-06-16 00:05:34 +08:00
parent c2de9d8e83
commit ff145300b4
3 changed files with 259 additions and 7 deletions
+5 -3
View File
@@ -362,8 +362,7 @@ where
symbol: &str,
snapshot: &crate::data::DailyMarketSnapshot,
) -> f64 {
if self.aiquant_rqalpha_execution_rules && self.execution_price_field == PriceField::Last
{
if self.aiquant_rqalpha_execution_rules && self.execution_price_field == PriceField::Last {
let start_cursor = self
.runtime_intraday_start_time
.get()
@@ -5395,7 +5394,10 @@ mod tests {
)
.expect("process target value");
assert_eq!(portfolio.position(symbol).map(|pos| pos.quantity), Some(21_400));
assert_eq!(
portfolio.position(symbol).map(|pos| pos.quantity),
Some(21_400)
);
let order = report.order_events.last().expect("target value order");
assert_eq!(order.requested_quantity, 200);
assert_eq!(order.filled_quantity, 200);
+19
View File
@@ -341,6 +341,8 @@ pub struct BacktestEngine<S, C, R> {
futures_cost_model: FuturesTransactionCostModel,
futures_validation_config: FuturesValidationConfig,
execution_quote_loader: Option<ExecutionQuoteLoader>,
execution_quote_request_cache:
BTreeSet<(NaiveDate, String, Option<NaiveTime>, Option<NaiveTime>)>,
}
impl<S, C, R> BacktestEngine<S, C, R> {
@@ -369,6 +371,7 @@ impl<S, C, R> BacktestEngine<S, C, R> {
futures_cost_model: FuturesTransactionCostModel::default(),
futures_validation_config: FuturesValidationConfig::default(),
execution_quote_loader: None,
execution_quote_request_cache: BTreeSet::new(),
}
}
@@ -553,12 +556,20 @@ where
symbols: &mut BTreeSet<String>,
) -> Result<(), BacktestError> {
symbols.retain(|symbol| {
let request_key = (execution_date, symbol.clone(), start_time, end_time);
if self.execution_quote_request_cache.contains(&request_key) {
return false;
}
if start_time.is_some() && end_time.is_none() {
return true;
}
!has_execution_quote_in_window(&self.data, execution_date, symbol, start_time, end_time)
});
if symbols.is_empty() {
return Ok(());
}
let requested_symbols = symbols.iter().cloned().collect::<Vec<_>>();
let request = ExecutionQuoteRequest {
date: execution_date,
start_time,
@@ -571,6 +582,14 @@ where
.expect("checked execution quote loader")
.as_mut()(request)?;
self.data.add_execution_quotes(quotes);
for symbol in requested_symbols {
self.execution_quote_request_cache.insert((
execution_date,
symbol,
start_time,
end_time,
));
}
Ok(())
}