Skip to content

fix: consume the first tick threshold so features align with bars - #68

Merged
Sean-Koval merged 1 commit into
mainfrom
work/microstructural-first-threshold
Sep 19, 2026
Merged

Sean-Koval merged 1 commit into
mainfrom
work/microstructural-first-threshold

Conversation

@Sean-Koval

Copy link
Copy Markdown
Contributor

Fixes #67.

Problem

MicrostructuralFeaturesGenerator::new_from_csv peeked at the first tick threshold instead of taking it from the iterator. After the first bar closed the same threshold was served again, so the next tick closed a one-tick bar. Thresholds [10, 20, 30] produced 4 rows, and every row after the first was misaligned with the bars that defined the thresholds.

Fix

Take the first threshold out of the iterator (what mlfinlab's generator does with next()).

Evidence

  • New test test_feature_generator_emits_one_row_per_tick_threshold: 30 synthetic ticks, thresholds [10, 20, 30], asserts average tick sizes [1, 2, 3]. On main it fails with [1, 2, 2, 3].
  • cargo test --workspace: 247 passed / 0 failed / 1 ignored. No existing expectation changed — the existing generator test only asserted non-empty output, which is why this went unnoticed.
  • cargo fmt --check and clippy (CI flags) clean.

Behavior change

Callers get one fewer row (the degenerate second row disappears) and rows now align one-to-one with tick_num_series.

Merge note

#64 puts an #[allow(clippy::unnecessary_to_owned)] on the initialiser line this PR rewrites, so the second of the two to merge will need a small conflict resolution.

🤖 Generated with Claude Code

new_from_csv read the first threshold with a peek and left it in the
iterator, so it was served again after the first bar closed and the next
tick emitted a spurious one-tick bar. Thresholds [10, 20, 30] produced four
rows, with every row after the first misaligned against the bars.

Take the first threshold out of the iterator, as mlfinlab's generator does.
The new test builds 30 synthetic ticks and asserts exactly three rows with
average tick sizes 1, 2, 3; it fails with [1, 2, 2, 3] before this change.

Fixes #67

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Sean-Koval
Sean-Koval merged commit c6ce253 into main Sep 19, 2026
7 checks passed
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.

MicrostructuralFeaturesGenerator emits a spurious one-tick bar: first tick threshold is used twice

1 participant