Skip to content

feat: add explicit futures variation-cash accounting - #167

Merged
stefan-jansen merged 136 commits into
mainfrom
codex/futures-variation-account
Oct 22, 2026
Merged

stefan-jansen merged 136 commits into
mainfrom
codex/futures-variation-account

Conversation

@stefan-jansen

@stefan-jansen stefan-jansen commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Owning issue

Closes #158. Advances #159 and #156. Dated roll execution and final migration closure remain separate work.

Outcome

Add explicit per-instrument futures variation cash to the existing Engine, Broker and AccountState. Existing contracts retain signed-notional accounting. Choose scheduled settlement events or mark/fill-driven payout. Account observations distinguish liquidation, notional, initial/maintenance margin, available funds and unsettled variation.

The same variation-fill rule now governs execution, submission reservations and queue projections. Schema 6 artifacts retain actual payout records and account observations, including combined corporate actions and benchmarks. Schema 2-5 readers remain covered. No legacy production dependency is added.

Regression and reference evidence

  • Existing fixed-margin validation ignored a declared $15,000 requirement in favor of $200,000 full notional. A public Engine failure on base 66b2134 now passes.
  • Public helper forwarding, liquidation versus exposure, atomic mark groups, unpaid-dividend availability and callback rollback have retained failing-base/passing-fix checks.
  • On previous PR head 04850b3, the expanded public financial suite has 15 failures and 50 passing controls. Reservation/simple-cash paths spent futures principal; scheduled scale/close projections lost variation basis. The repair shares the actual fill transition, reserves fees once, refreshes from actual observation state and preserves rollback.
  • Eight captured actual Zipline Reloaded 3.2.0 runs cover long, short, close and scale/partial/flip, each with zero or fixed per-future fees. Complete cash, NAV, position basis, mark and fill traces match exactly without widened tolerances. Actual installed Data snapshot and contract-preparation workflows are included.

Compatibility and method choices

New ContractSpec fields are keyword-only and opt-in. Scheduled exchange settlement and mark-driven reference payout remain distinct. Reads never pay; settlement marks do not become execution quotes; margin is collateral rather than a fee. The single cash account does not convert currencies. The callback adapter retains its explicit unconstrained entry profile; native Engine supports constrained margin. End-of-data does not invent liquidation fills.

The continuous-root CME workload still lacks a dated chain/roll map for the Zipline comparison. This PR makes no universal futures-parity or new speed claim. The runnable futures-accounting guide documents the next-version source boundary, absent from published 0.1.12 and the preserved pending 0.1.13 candidate.

Checks actually run

  • Source 5e39dd80: full suite: 3,086 passed,85 optional skips,5 deselected. Its 14 source-bound evidence failures were resolved through fresh reports; all 67 targeted evidence/compatibility checks then pass. Every global and critical coverage threshold passes.
  • Focused financial, default, rollback and ownership checks: 327 passed,8 optional skips. Ruff, formatting,ty, compatibility generation and normal hooks pass.
  • Isolated 5e39 wheel: 261 passed with warnings as errors, including actual installed Data and all 16 captured-reference variants.
  • Fresh Backtest: 66 synthetic and 17 production comparisons pass against hash-verified frozen reference outputs. Reference frameworks and licensed authentication were not rerun.
  • All accepted publication timing samples remain unchanged, measurement SHA256 2764a504d315ca55a1bc077073c138de959be647816b651a819d4bde21dfb4e1. The prior 7dc bounded ETF/CME source diagnostics and explicit follow-up source review support reuse; they are not relabeled as 5e measurements or new gains.
  • Strict docs build, executed source/installed examples, 11,554 rendered links/44 external destinations and version/source identity pass at their recorded revisions. Final-head hosted documentation checks remain required.
  • Wheel/sdist builds and artifact validation pass; the earlier 7dc independent rebuild is byte-identical. Runtime dependency audit has no findings; source security scan is refreshed for the repair.
  • Every applicable exact-head hosted supported-platform, compatibility, coverage, docs, security and package gate. Ordinary guarded merge waits for these checks.

AI assistance and release

OpenAI Codex assisted with implementation, reference capture, tests, documentation, source review and this PR text. Review used original source, independent account arithmetic and the actual public workflows above. Final-revision gates remain required. No release, tag, publication or deployment is included.

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 01:15

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 marked this pull request as draft October 22, 2026 01:34
@stefan-jansen
stefan-jansen marked this pull request as ready for review October 22, 2026 01:36
@stefan-jansen
stefan-jansen merged commit dcb5e96 into main Oct 22, 2026
43 checks passed
@stefan-jansen
stefan-jansen deleted the codex/futures-variation-account branch October 22, 2026 02:05
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.

Explicit variation-cash futures account method

2 participants