Skip to content

Execute dated futures rolls and explicit lifecycle boundaries - #168

Merged
stefan-jansen merged 145 commits into
mainfrom
codex/dated-futures-rolls
Oct 22, 2026
Merged

stefan-jansen merged 145 commits into
mainfrom
codex/dated-futures-rolls

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

Summary

Implement dated-contract execution through the existing Broker, AccountState and transactional scheduler:

  • Broker.roll_position submits two ordinary non-atomic market legs, preserves causal selection clocks and source facts, and returns original orders on an unchanged ID retry.
  • Actual roll projections retain order IDs, every partial fill, fees, execution instants, rejection and completion. Schema 7 persists this ledger with content identity and actual-fill validation; existing schemas 2 through 6 remain readable.
  • Opt-in FuturesLifecyclePolicy closes or rolls at a declared physical notice/last-trade/auto-close/expiry boundary. It cancels old pending orders and prevents subsequent exposure increases. It never creates a quote, synthetic fill or terminal liquidation. Missing quotes remain pending; boundaries beyond captured data preserve open holdings.
  • Actual Data preparation supplies preceding-session volume choices, publication-aware OI and normalized raw dated prices. Future metric perturbations leave earlier decisions and fills unchanged. Integer source IDs are explicitly namespaced on both sides of the handoff.
  • Add a runnable guide and original published Zipline 3.2.0 calendar/volume/expiry capture. Native raw-quote close matches the captured complete fills, cash and NAV. Virtual-chain selection alone does not move a held position. Original data-portal synthetic expiry cleanup and missing native execution quotes remain an explicit method difference.

Closes #159. Advances the cross-workflow acceptance in #156 and #160.

Executed evidence

Reviewed runtime source: f277d8a2c815f3e8d593e3c119344abff7b06396; final evidence/static-check revision: d9eb54379c297f797106a727f8df78c2381602c8. Their package runtime source is identical.

  • Actual public Engine failure controls: missing roll API on the earlier account base; artifact roundtrip omitted roll capture before schema 7; a future lifecycle boundary erroneously failed after captured data before corrected binding; missing Pandas timestamps were accepted on naive clocks before the final input repair.
  • 78 focused financial/lifecycle/clock/ownership checks pass, including long/short, signed-notional/variation, complete/pending/rejected legs, integer/fractional partial fills, immediate/next-bar mode, exact/between-observation boundaries, rollback, and missing metadata. Combined benchmark/actions/variation/roll artifacts roundtrip with independently reconciled cash and NAV.
  • Actual published zipline-reloaded==3.2.0 capture reproduces all three cases; native reference checks pass. The checked capture produces the same retained output as the original capture.
  • Wheel and independently installed sdist 0.1.13.dev170+gf277d8a2c: 218 tests pass each under isolated imports and warnings as errors. This includes actual Data 0.2.2.dev21+gc3b9db80a and published Specs 0.2.0, not a reconstructed producer fixture.
  • Full source coverage run: 3,138 pass, 87 optional skips, 5 deselected before final evidence/static registration repair. Its 15 failures were stale source evidence and the missing capture-script check registration. Fresh evidence and all 48 affected compatibility/evidence/static checks pass after repair. Global and critical-module branch coverage thresholds pass.
  • All required Ruff, formatting and ty checks include the manual reference capture. Dependency audit and final source security scan pass without exceptions. Complete artifact manifests and package metadata checks pass.
  • Strict docs build, every installed documentation example, 11,685 rendered links and 47 external destinations pass. No docs were deployed.
  • Fresh 66 synthetic and 17 production Backtest pairs pass against hash-verified retained native outputs. No reference timing run or licensed authentication occurred. All 17 measured output identities and every accepted timing record remain unchanged. The bounded default-path source review finds no material performance effect; existing performance claims and samples remain in place.

Final-head hosted source, platform, dependency, package and documentation checks remain mandatory before ordinary guarded merge. This PR makes no release, deployment, arbitrary-chain parity or new speed claim. The preserved 0.1.13 publication candidate is unchanged.

AI assistance

OpenAI Codex assisted with implementation, source/reference inspection, tests and documentation. The implementing maintainer reviewed the financial definitions, complete diff, actual producer/consumer workflows, and retained failing-base/passing-fix evidence.

Adopt the immutable Specs temporal contract, keep legacy config payloads readable, and make explicit None select observation semantics. Qualify the next API boundary separately from the retained 0.1.13 candidate.
Regenerate lock metadata offline after the direct immutable source dependency. Preserve all other package versions and source identities; the public locked Zipline builder now succeeds.
Include first-period execution costs in returns and drawdown without adding a synthetic bar. Store the baseline in schema 3 and preserve schema 2 and beta readers. Adds real Engine failing-base regression coverage for issue #155. Also includes the requested maintainer batching guidance.
…xports

Enable explicit bar capture while retaining complete account observation keys, including all-cash dates. Extend the existing schema 3 artifact with optional holdings and strict keys, retain unavailable legacy capture, and preserve equal-time execution order. Advances #155; capital flows and installed consumer qualification remain open.
…ication

Reproduce the shared Python 3.15 failure through uv resolution. Bind selected packages, artifacts, markers and lock declarations while excluding the resolver prerelease permission alone. Preserve raw identities and all 17 accepted measurement records, and keep actual dependency drift rejection. Full suite: 2320 passed, 14 skipped. Fixes qualification of #151.
Apply validated delta/target schedules before decisions using actual marked NAV and preserve pre/post-flow valuations. Chain subperiod returns, retain reported NAV separately from investment wealth, and persist ordered flow applications. Extend accounting invariants to include independently recorded external capital without changing their tolerance. Adds public Engine and artifact regressions and a runnable guide. Advances #155; full qualification and migration integration remain open.
Use a real uv-generated self-contained lock instead of requiring every platform package and build backend in the runner cache. Preserve the failing-base producer operation and the actual dependency-drift rejection control. Addresses the clean-runner failures at 7233675 without changing validator or runtime behavior.
Capture the multiplier and declared currency used for each fill and export signed quantity. Preserve unknown legacy units and cost inclusion rather than reconstructing them from later configuration. Adds actual Engine/Parquet unit checks. Advances #155.
Capture post-fill and last-observed-session holdings through the existing account and fill journal, with explicit completeness and sequence keys. Keep investment returns on the original bar timeline and roll back observations with failed immediate callbacks. Reuse one marked snapshot implementation; preserve a valid zero mark in both carried valuations and open-trade PnL. The zero-mark regression fails twice on b49307a; focused account/lifecycle checks pass. Advances #155.
Keep detailed mark provenance out of ordinary valuation loops and enable timestamp history only when requested. Custom/legacy feeds may omit the new optional capital-events attribute. The real legacy feed run fails before the fix and passes afterward; 39 account/lifecycle/runtime checks pass, including the existing runtime regression gate. Advances #155.
…sions

Add Broker.record using the existing journal, callback transaction and portable artifact encoding. Retain carried values on actual bar keys, preserve nonfinite values, expose decoded records, and reject unsupported values before mutation. Persist the optional versioned component with strict observation checks and a runnable guide. Advances #155 and the record adapter foundation of #156; 131 focused checks pass.
Preserve accepted performance samples after the bounded default-path review. Qualify raw action ledger, exact input preparation and observable account/artifact contracts.

Closes #157
Copilot AI balanced review requested due to automatic review settings October 22, 2026 02:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@stefan-jansen
stefan-jansen merged commit f6ee2d6 into main Oct 22, 2026
43 checks passed
@stefan-jansen
stefan-jansen deleted the codex/dated-futures-rolls branch October 22, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Executable dated contracts, causal rolls and notice/expiry

2 participants