Day 142 — The event loop, and the order things happen in

Saturday, 26 December 2026 · Week 21 of 52 · The research harness · Study day · 60 min

The sequence you sketched last night is the whole design; everything else in the engine is bookkeeping, and a wrong sequence is a leak that no test outside the engine will find.

What you should be able to do tonight

  • Implement a session-level event loop where the sequence of read, decide, order, fill and mark is fixed and explicit.
  • Show that the engine cannot compute a signal from data timestamped after the decision point, by construction rather than by convention.

Tasks 60 min

40 min Write qlib/backtest/engine.py: for each session, present the strategy with a read-only view of the store as of the decision timestamp, collect orders, pass them to a fill model, apply fills to a portfolio, then mark to market at the close. The strategy never receives the store itself, only the as-of view, which is what makes the leak impossible rather than unlikely.

20 min Port the trend follower to it and reconcile against the vectorised version on a period where the two should agree. Any difference is either an assumption you now represent correctly or a bug, and separating those two is the exercise.

The running strategy

qlib/backtest/engine.py is the event loop the rest of the year runs on. The strategy sees an as-of view rather than the store, so look-ahead is prevented by the interface rather than by care.

Resources

Deliverable

A working session-level event loop with the trend follower ported to it and reconciled against the vectorised version.

Checkpoint

In your engine, what object does a strategy receive, and why does its type make look-ahead impossible?

Prepare for tomorrow

Ten minutes tonight so Day 143, Sunday, 27 December 2026 starts clean. This is what the evening email sends you.

Write down what price your backtests have been assuming for fills, and what the alternatives are.

For a market-on-close order, name three prices you could plausibly use and say which is most honest.

One paragraph, no code.