Add process event stream for backtests

This commit is contained in:
boris
2026-04-23 01:58:40 -07:00
parent e5fe1f0432
commit 23ba74909d
6 changed files with 384 additions and 11 deletions

View File

@@ -6,8 +6,8 @@ use chrono::NaiveDate;
use fidc_core::{
BacktestConfig, BacktestEngine, BenchmarkSnapshot, BrokerSimulator, CandidateEligibility,
ChinaAShareCostModel, ChinaEquityRuleHooks, DailyFactorSnapshot, DailyMarketSnapshot, DataSet,
Instrument, PriceField, ScheduleRule, ScheduleStage, Strategy, StrategyContext,
StrategyDecision,
Instrument, PriceField, ProcessEventKind, ScheduleRule, ScheduleStage, Strategy,
StrategyContext, StrategyDecision,
};
fn d(year: i32, month: u32, day: u32) -> NaiveDate {
@@ -302,7 +302,7 @@ fn engine_runs_strategy_hooks_in_daily_order() {
},
);
engine.run().expect("backtest succeeds");
let result = engine.run().expect("backtest succeeds");
assert_eq!(
log.borrow().as_slice(),
@@ -319,6 +319,30 @@ fn engine_runs_strategy_hooks_in_daily_order() {
"settlement:2025-01-03",
]
);
assert_eq!(result.process_events.len(), 30);
assert_eq!(
result.process_events[..15]
.iter()
.map(|event| &event.kind)
.collect::<Vec<_>>(),
vec![
&ProcessEventKind::PreBeforeTrading,
&ProcessEventKind::BeforeTrading,
&ProcessEventKind::PostBeforeTrading,
&ProcessEventKind::PreOpenAuction,
&ProcessEventKind::OpenAuction,
&ProcessEventKind::PostOpenAuction,
&ProcessEventKind::PreOnDay,
&ProcessEventKind::OnDay,
&ProcessEventKind::PostOnDay,
&ProcessEventKind::PreAfterTrading,
&ProcessEventKind::AfterTrading,
&ProcessEventKind::PostAfterTrading,
&ProcessEventKind::PreSettlement,
&ProcessEventKind::Settlement,
&ProcessEventKind::PostSettlement,
]
);
}
#[test]