Repository navigation
14.1: aggregator improvements - #25
Merged
Merged
Conversation
MathisWellmann
commented
Nov 12, 2026
Owner
- components: bipower variation and quarticity act on market events
- aggregator: start the seq of the candles at a given number
- aggregator: report events out of time order as an error
- tests: save and restore the aggregator with bincode and real prices
BipowerVariation and RealizedQuarticity took any TakerTrade, while every other trade component takes AsTrade events. So a candle over MarketEvent<T, Q> with them did not compile, and a fused trade and quote candle could not hold the jump-robust volatility estimates. They now skip quotes like RealizedVariance does. Every TakerTrade is AsTrade, so plain trade candles keep working.
seq counts the candles from the start of an aggregator. A process that continues a series without the saved aggregator, e.g. after the loss of its checkpoint, restarted the numbers at 0. A store that removes duplicates by (series, rule, seq) would then replace old candles with new ones. with_next_seq continues the numbers. It must be called before the first event, so the numbers cannot skip or repeat. The docs say that only a restored aggregator also keeps the rule state, and that a fresh one matches the old candles only from a point that does not depend on the past, e.g. the start of an aligned period.
update and advance_to panic on an event or a watermark earlier than the latest time. In a live process that serves many symbols, one late event then stops all of them, and after a restart the same event can stop the process again. try_update and try_advance_to return OutOfOrder instead and change nothing, so the caller can drop or log the event. latest_timestamp lets the caller check the order itself. OutOfOrder is a type of its own, because Error is not non_exhaustive and a new variant would break exhaustive matches.
The restart test saved the aggregator as JSON and used prices such as 117.0. serde_json without float_roundtrip parses some prices 1 ulp off, and the restored aggregator then closes other candles. Short decimal prices hid this; a probe with a random walk price showed it. The test now saves with bincode, which stores every f64 exactly, compares the bars byte for byte, uses a random walk price with varied sizes, and covers more components with f64 state, also a candle of trades and quotes. With plain JSON both restart tests now fail. The README says to save the state in an exact format.
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.