Repository navigation
fix(features): compute Roll spread with current-window covariance - #85
Merged
Merged
Conversation
The estimator subtracted each bar's own trailing mean and then averaged those products, which is not the covariance of the current window. The spread now uses E[xy] - E[x]E[y] over that window. Co-authored-by: quantum-like <[email protected]>
The registered warm-up was twice the window because the old estimator nested two rolling means. The window covariance is first defined one bar after the lag is available. Co-authored-by: quantum-like <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #84. Supersedes the Roll-spread portion of #71.
Calculate serial covariance over the same current window, rather than averaging products whose points were each demeaned by different trailing windows. Keep the corrected period+1 lookback metadata. Preserve the original source correction and authorship.
Also keep missing covariance windows undefined: an actual CSV NaN price previously made the estimator report zero spread, unlike an empty CSV field. Guard NaN covariance before nonnegative clipping. Finite nonnegative covariance still produces zero as intended; unknown windows produce null.
At head 7c3d66a, after incorporating qualified main eed81dc, all 39 microstructure tests pass. Sixteen permanent real-CSV cases cover periods 1/2/4/7 and eager/lazy workflows. Before the additional producer repair, all eight NaN cases failed and all eight empty-field controls passed. The oracle uses NumPy's independently centered covariance with ddof=0. The original finite-window regression also uses that independent implementation.
The full suite passes 4,215 tests with 57 intentional deselections. Ruff, formatting, ty, all-file hooks, lock validation, package build/import, twine metadata checks and strict MkDocs pass. The isolated built wheel passes the complete public CSV-gap reproduction. Fresh hosted qualification is required before merge. Earlier checks remain pinned to original submitted revision b6ad633.
Numerical and missing-value behavior changes warrant inclusion in the eventual qualified patch release. This PR does not publish a release or deploy documentation.
AI assistance: Codex reproduced the public CSV behavior, inspected source and overlap, implemented the focused missing-window repair and permanent independent regressions, ran checks and drafted this description. Original Cursor Agent source-fix authorship is retained; the lookback and supplemental repair commits remain separately attributed.