Add process event stream for backtests
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -2,8 +2,8 @@ use chrono::NaiveDate;
|
||||
use fidc_core::{
|
||||
BenchmarkSnapshot, BrokerSimulator, CandidateEligibility, ChinaAShareCostModel,
|
||||
ChinaEquityRuleHooks, DailyFactorSnapshot, DailyMarketSnapshot, DataSet, Instrument,
|
||||
IntradayExecutionQuote, OrderIntent, PortfolioState, PriceField, SlippageModel,
|
||||
StrategyDecision,
|
||||
IntradayExecutionQuote, OrderIntent, PortfolioState, PriceField, ProcessEventKind,
|
||||
SlippageModel, StrategyDecision,
|
||||
};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
@@ -416,6 +416,11 @@ fn broker_cancels_buy_when_open_hits_upper_limit() {
|
||||
.reason
|
||||
.contains("open at or above upper limit")
|
||||
);
|
||||
assert!(report.process_events.iter().any(|event| {
|
||||
event.kind == ProcessEventKind::OrderUnsolicitedUpdate
|
||||
&& event.symbol.as_deref() == Some("000002.SZ")
|
||||
&& event.side == Some(fidc_core::OrderSide::Buy)
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -989,6 +994,22 @@ fn broker_splits_intraday_quote_fills_and_tracks_commission_by_order() {
|
||||
.iter()
|
||||
.any(|item| item.contains("order_split_fill symbol=000002.SZ side=buy"))
|
||||
);
|
||||
assert_eq!(
|
||||
report
|
||||
.process_events
|
||||
.iter()
|
||||
.filter(|event| event.kind == ProcessEventKind::Trade)
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
assert!(report.process_events.iter().any(|event| {
|
||||
event.kind == ProcessEventKind::OrderPendingNew
|
||||
&& event.symbol.as_deref() == Some("000002.SZ")
|
||||
}));
|
||||
assert!(report.process_events.iter().any(|event| {
|
||||
event.kind == ProcessEventKind::OrderCreationPass
|
||||
&& event.symbol.as_deref() == Some("000002.SZ")
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user