Day 144 — Orders have a lifecycle, and positions are derived
Monday, 28 December 2026 · Week 21 of 52 · The research harness · Study day · 60 min
Storing positions and inferring trades is the design that makes reconciliation impossible in phase 10, so the engine stores fills and derives everything else from them.
What you should be able to do tonight
- Represent an order through its full lifecycle and derive positions, cash and profit from the fill record alone.
- Show that positions, cash and mark-to-market value satisfy an accounting identity at every step.
Tasks 60 min
35 min Implement the order and fill records in qlib/backtest/: an order carries symbol, side, quantity, order type, submission timestamp and state; a fill carries order id, timestamp, quantity, price and fees. Persist fills to fills.parquet. Positions and cash are derived from fills, never stored independently, which is the decision that makes phase 10’s reconciliation possible.
25 min Write the accounting invariant as a test: at every session, cash plus the mark-to-market value of positions minus the initial capital must equal cumulative realised and unrealised profit, to a tolerance. This test catches more bugs than any other single test in the engine.
The running strategy
Fills are the primary record and everything else is derived from them, written to fills.parquet. The accounting identity is asserted at every session, which is the invariant phase 10 reconciles the live account against.
Resources
- PyArrow documentation tool
- pytest documentation tool
Deliverable
Order and fill records with fills.parquet written, and a passing accounting identity test at every session.
Checkpoint
Why store fills and derive positions rather than the other way round? Give the answer in terms of what you will need in July.
Prepare for tomorrow
Ten minutes tonight so Day 145, Tuesday, 29 December 2026 starts clean. This is what the evening email sends you.
List what a strategy result object should carry so that a tearsheet, a milestone report and a comparison table can all be built from it without rerunning anything.
Eight fields is about right.
Look at what pyfolio-reloaded expects as input for comparison.