From effa0c6456dbfe4297f3189b6e61bbfc51f48c0c Mon Sep 17 00:00:00 2001 From: boris Date: Sun, 13 Sep 2026 11:21:09 +0800 Subject: [PATCH] test(engine): validate quote demand across different account capital --- crates/fidc-core/src/engine.rs | 33 +++++++++---------- .../fidc-core/tests/decision_quote_preload.rs | 11 ++++--- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/crates/fidc-core/src/engine.rs b/crates/fidc-core/src/engine.rs index e781712..05dac48 100644 --- a/crates/fidc-core/src/engine.rs +++ b/crates/fidc-core/src/engine.rs @@ -1,5 +1,4 @@ use std::collections::{BTreeMap, BTreeSet}; -use std::sync::Arc; use chrono::{Datelike, Duration, NaiveDate, NaiveTime}; use serde::{Deserialize, Serialize}; @@ -2612,23 +2611,23 @@ where if self.execution_quote_loader.is_some() && !decision_quote_times.is_empty() { let decision_quote_symbols = self.strategy.decision_quote_symbols(&StrategyContext { - execution_date, + execution_date, + decision_date, + decision_index, + data: &self.data, + portfolio: &portfolio, + futures_account: self.futures_account.as_ref(), + open_orders: &on_day_open_orders, + dynamic_universe: self.dynamic_universe.as_ref(), + subscriptions: &self.subscriptions, + process_events: &process_events, + active_process_event: None, + active_datetime: stage_datetime( decision_date, - decision_index, - data: &self.data, - portfolio: &portfolio, - futures_account: self.futures_account.as_ref(), - open_orders: &on_day_open_orders, - dynamic_universe: self.dynamic_universe.as_ref(), - subscriptions: &self.subscriptions, - process_events: &process_events, - active_process_event: None, - active_datetime: stage_datetime( - decision_date, - default_stage_time(ScheduleStage::OnDay), - ), - order_events: result.order_events.as_slice(), - fills: result.fills.as_slice(), + default_stage_time(ScheduleStage::OnDay), + ), + order_events: result.order_events.as_slice(), + fills: result.fills.as_slice(), })?; self.ensure_execution_quotes_for_symbols_at_times( execution_date, diff --git a/crates/fidc-core/tests/decision_quote_preload.rs b/crates/fidc-core/tests/decision_quote_preload.rs index d39f15b..fe34c0b 100644 --- a/crates/fidc-core/tests/decision_quote_preload.rs +++ b/crates/fidc-core/tests/decision_quote_preload.rs @@ -174,19 +174,21 @@ fn runtime_account_dependent_quote_scope_uses_the_actual_account() { } else { BTreeSet::new() }) } fn on_day(&mut self, ctx: &StrategyContext<'_>) -> Result { - assert!(ctx.data.execution_quotes_on(ctx.execution_date, "000001.SZ").iter().any(|quote| - quote.timestamp.time()==t(10,17,59) && quote.last_price==10.0), - "actual account-dependent quote scope must be loaded before decision"); + let loaded = ctx.data.execution_quotes_on(ctx.execution_date, "000001.SZ").iter().any(|quote| + quote.timestamp.time()==t(10,17,59) && quote.last_price==10.0); + assert_eq!(loaded, ctx.portfolio.cash() < 50_000.0, + "quote scope must match this account, not a fixed-capital planning account"); Ok(StrategyDecision::default()) } } let date = d(2026, 1, 5); + for initial_cash in [10_000.0, 100_000.0] { let broker = BrokerSimulator::new_with_execution_price( ChinaAShareCostModel::default(), ChinaEquityRuleHooks, PriceField::Close, ).with_volume_capacity_mode(fidc_core::execution_capacity::VolumeCapacityMode::SessionCapacityAudit) .with_matching_type(MatchingType::CurrentBarClose); let config = BacktestConfig { - initial_cash:10_000.0, benchmark_code:"000852.SH".into(), + initial_cash, benchmark_code:"000852.SH".into(), start_date:Some(date), end_date:Some(date), decision_lag_trading_days:0, execution_price_field:PriceField::Close, }; @@ -198,6 +200,7 @@ fn runtime_account_dependent_quote_scope_uses_the_actual_account() { trading_phase:Some("continuous".into()), }).collect())); engine.run().expect("account-dependent quote planning"); + } } #[test]