feat(bars): add fixed tick run bar sampler#13
Merged
Conversation
…ars) Run bars previously had only the adaptive (alpha-EWMA) TickRunBarSampler, which threshold-spirals on persistently one-sided flow — the same instability the imbalance family already addresses with its Fixed/Window variants. This adds the run-bar analog of FixedTickImbalanceBarSampler: a bar forms when max(cumulative_buys, cumulative_sells) within the bar reaches a fixed threshold (cumulative per AFML; no reset on direction change). Stable, reproducible, predictable bar count, no feedback loop. Exported from ml4t.engineer.bars. 9 tests cover init validation, schema, threshold monotonicity, cumulative (not consecutive) counting, and the key stability property: an all-one-side stream yields exactly floor(n/T) bars instead of spiraling. Full bars suite: 156 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new fixed-threshold tick run bar sampler to the ml4t.engineer.bars sampling toolkit, aiming to provide a stable alternative to the adaptive AFML tick run bar algorithm.
Changes:
- Implement
FixedTickRunBarSamplerbacked by a Numba-compiled fixed-threshold run-bar indexer. - Export the new sampler from
ml4t.engineer.barsandml4t.engineer.bars.run. - Add focused tests for fixed tick run bars and update the
0.1.0b9changelog entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/ml4t/engineer/bars/run.py |
Adds the fixed-threshold run bar index calculation and the FixedTickRunBarSampler implementation. |
src/ml4t/engineer/bars/__init__.py |
Re-exports FixedTickRunBarSampler from the public ml4t.engineer.bars surface. |
tests/bars/test_run_bars.py |
Adds initialization, validation, stability, and incomplete-bar tests for the new sampler. |
CHANGELOG.md |
Documents the new sampler under 0.1.0b9 and updates version comparison links. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+13
to
+19
| ### Fixed | ||
| - Public package metadata links now point to the `ml4t/engineer` repository and | ||
| published documentation | ||
| - Added the missing MIT license file to the source distribution | ||
| - Synced lockfile metadata with relaxed dependency bounds | ||
| - Reduced pytest warning noise for performance markers and cyclical feature | ||
| metadata |
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.
Summary
FixedTickRunBarSamplerfor stable, fixed-threshold tick run bars.ml4t.engineer.bars.v0.1.0b9changelog entry.Validation
uv run --locked pytest tests/bars/test_run_bars.py -quv run --locked ruff check src/ml4t/engineer/bars tests/bars/test_run_bars.py