分离过程事件分发与结果保留
This commit is contained in:
@@ -14,8 +14,8 @@ use fidc_core::{
|
||||
IntradayExecutionQuote, IntradayOrderBookDepthLevel, MatchingType, NumericFactorMap,
|
||||
OpenOrderView, OrderIntent, OrderSide, OrderStatus, PlatformExprStrategy,
|
||||
PlatformExprStrategyConfig, PlatformTradeAction, PortfolioState, PriceField, ProcessEvent,
|
||||
ProcessEventBus, ProcessEventKind, ScheduleRule, ScheduleStage, ScheduleTimeRule, Strategy,
|
||||
StrategyContext, StrategyDecision,
|
||||
ProcessEventBus, ProcessEventKind, ProcessEventRetention, ScheduleRule, ScheduleStage,
|
||||
ScheduleTimeRule, Strategy, StrategyContext, StrategyDecision,
|
||||
};
|
||||
|
||||
fn d(year: i32, month: u32, day: u32) -> NaiveDate {
|
||||
@@ -1199,6 +1199,7 @@ fn engine_runs_strategy_hooks_in_daily_order() {
|
||||
)
|
||||
.expect("dataset");
|
||||
|
||||
let compact_data = data.clone();
|
||||
let log = Rc::new(RefCell::new(Vec::new()));
|
||||
let strategy = HookProbeStrategy { log: log.clone() };
|
||||
let broker = BrokerSimulator::new_with_execution_price(
|
||||
@@ -1238,6 +1239,42 @@ fn engine_runs_strategy_hooks_in_daily_order() {
|
||||
]
|
||||
);
|
||||
assert_eq!(result.process_events.len(), 36);
|
||||
|
||||
let compact_strategy = HookProbeStrategy {
|
||||
log: Rc::new(RefCell::new(Vec::new())),
|
||||
};
|
||||
let compact_broker = BrokerSimulator::new_with_execution_price(
|
||||
ChinaAShareCostModel::default(),
|
||||
ChinaEquityRuleHooks::default(),
|
||||
PriceField::Open,
|
||||
);
|
||||
let mut compact_engine = BacktestEngine::new(
|
||||
compact_data,
|
||||
compact_strategy,
|
||||
compact_broker,
|
||||
BacktestConfig {
|
||||
initial_cash: 100_000.0,
|
||||
benchmark_code: "000300.SH".to_string(),
|
||||
start_date: Some(date1),
|
||||
end_date: Some(date2),
|
||||
decision_lag_trading_days: 0,
|
||||
execution_price_field: PriceField::Open,
|
||||
},
|
||||
)
|
||||
.with_process_event_retention(ProcessEventRetention::Business);
|
||||
let compact_result = compact_engine.run().expect("compact backtest succeeds");
|
||||
assert!(compact_result
|
||||
.process_events
|
||||
.iter()
|
||||
.all(|event| event.kind.is_business_lifecycle()));
|
||||
assert!(compact_result
|
||||
.process_events
|
||||
.iter()
|
||||
.any(|event| event.kind == ProcessEventKind::OnDay));
|
||||
assert!(!compact_result
|
||||
.process_events
|
||||
.iter()
|
||||
.any(|event| event.kind == ProcessEventKind::PreBeforeTrading));
|
||||
assert_eq!(
|
||||
result.process_events[..18]
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user