Chapter 4: Event-Driven Backtesting Principles¶
This chapter is currently maintained in Chinese first.
- Chinese chapter: 第 4 章:事件驱动回测原理 (Event-Driven Architecture)
- Fill mode note:
fill_policy=<FillMode>(one ofCurrentClose(),NextOpen(),NextClose(),NextAverage(),NextHighLowMid()) is now the recommended public style. - Configuration layering note (highest to lowest): order-level > strategy-map level (
strategy_*) > run-level > market defaults. - Commission layering note:
commission_policyis now the recommended run-level entry forpercent,fixed, andper_unit; legacycommission_rateremains as a percent-only shorthand. - T+1 scope note:
t_plus_onecurrently remains a run/market-level switch, not a per-strategy layered setting. - Time ordering note:
- The event loop orders and advances time in UTC.
- Structured fields such as
event_time_iso,bar.timestamp_iso, andtrade.timestamp_isoare intentionally UTC ISO 8601 strings. - Local timezone conversion is a display concern, handled by helpers like
self.now,self.to_local_time(...), andself.format_time(...). - In short: UTC keeps the engine correct; local time keeps the output readable.
- Bar timestamp note: a bar is stamped at the end of its interval and carries
interval_start; ticks aggregated withfreq=are bucketed right-closed(S, E]and stamped atE(a tick at exactly 09:31:00 belongs to the 09:30-09:31 bar). Live aggregation also uses end stamps andflush_dueemits an overdue bar 2 seconds after its end, except the closing bar: ticks withinday_close_delay − 5seconds after the close are merged into it and it is emitted 2 seconds after that window ends (with the default 60 seconds, ticks up to 15:00:55 count and the bar is emitted at 15:00:57); a backtest whose data stops mid-interval does not flush the last partial bar. - Textbook home: Chinese textbook index
- Practice links:
- Primary example: examples/textbook/ch04_comparison.py
- Extended example: examples/25_streaming_backtest_demo.py
- Functional twin example: examples/textbook/ch04_comparison_functional.py
- Guide: Data Guide