Repository navigation
Improve consolidator registration ergonomics: quote-to-trade bar adaptation, registration-time period validation, calendar periods in RegisterIndicator - #9675
Open
jhonabreul wants to merge 4 commits into
Conversation
- Adapt trade bar consolidators and indicators to quote-only feeds (forex, cfd) by collapsing quote bars into mid-point trade bars with zero volume (new QuoteBarToTradeBarAdapter), instead of rejecting the registration with a type mismatch error - Validate fixed time span consolidator periods against the subscription period at registration time, mirroring the check PeriodCountConsolidatorBase performs when the first data point arrives, so invalid setups fail in Initialize instead of mid-backtest - Accept calendar periods (Calendar.WEEKLY/MONTHLY, custom functions) in RegisterIndicator and ResolveConsolidator, in C# overloads and in the Python register_indicator path, like Consolidate already does - Throw a clear ArgumentNullException for null symbols (e.g. Future.Mapped before the first mapping) instead of an NRE, and suggest Consolidate()/self.consolidate() in the type mismatch error
7 of 11 tasks
…or adapters the identity of the consolidator they wrap - QuoteDerivedTradeBar: trade bars collapsed from quote bars throw on Volume access instead of reporting zero - TradeBarConsolidator keeps consolidated bars volume-less when fed collapsed bars - ConsolidatorAdapterBase: adapters equal their wrapped consolidator and share its hash code - ConsolidatorIdentityComparer backs the registered consolidator collections so lookups work from either side - Period validation runs on the user's consolidator before it is wrapped
jhonabreul
marked this pull request as ready for review
October 13, 2026 19:21
…y the registration paths - QuoteDerivedTradeBar reads the quote bar mid-point prices directly instead of going through Collapse() - Drop the per-registration trace log from SubscriptionManager.AddConsolidator - Python RegisterIndicator tries the calendar conversion before the throwing timedelta cast
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.
Description
Consolidator registration on quote-only feeds (forex, cfd) and with mismatched periods fails late or needlessly. The engine can adapt type mismatches, validate periods at registration, accept calendar periods in
RegisterIndicator, and reject null symbols clearly.The change:
SubscriptionManager.AddConsolidatoradapts trade bar consolidators to quote-only feeds through a newQuoteBarToTradeBarAdapter.QuoteBaris collapsed into an internalQuoteDerivedTradeBar: mid-point prices, and reading or writingVolumethrowsInvalidOperationException.TradeBarConsolidatorkeeps its consolidated bar volume-less when fed collapsed bars.QCAlgorithm.RegisterIndicator<T>does the same collapse at the indicator layer (e.g.self.mass(symbol, resolution=Resolution.HOUR)on a cfd).ConsolidatorAdapterBase, which equals the consolidator it wraps and shares its hash code, so users remove the consolidator they hold.ConsolidatorIdentityComparerbacksSubscriptionDataConfig.Consolidatorsand the scan dictionary, so lookups match from either side (ConcurrentSetnow accepts a comparer).Initialize.RegisterIndicator/ResolveConsolidatoraccept calendar rules (Calendar.WEEKLY,Calendar.MONTHLY, custom), in C# and Python.Consolidate(), and a null symbol (e.g.Future.Mappedbefore the first mapping) throwsArgumentNullExceptionexplaining the likely cause.BaseData.IsFillForwardsetter is now protected so the collapsed bar can overrideClone(bool)without touching volume.Important
Known limits of the adapter identity
adapter.Equals(wrapped)is true, butwrapped.Equals(adapter)is false.==/ReferenceEqualsbetween the adapter and the wrapped consolidator stay false.SubscriptionDataConfig.Consolidatorsand the scan dictionary).Related Issue
N/A
Motivation and Context
The engine has all the information to adapt or fail fast at registration, and the late period error can kill a backtest months of simulated time in.
Requires Documentation Change
register_indicatordocs can mention calendar periods. The quote-to-trade adaptation is transparent, except thatvolumeon the collapsed bars throws.How Has This Been Tested?
ConsolidatorAutoAdaptationRegressionAlgorithm(C# + Python): trade bar consolidator andMassIndexon EURUSD receive collapsed bars, and the bars throw on volume.RegisterIndicatorWithCalendarRegressionAlgorithm(C# + Python): weekly RSI registered withCalendar.WEEKLYupdates when the week boundary is crossed.ConsolidatorPeriodValidationRegressionAlgorithm(C# + Python): 10-second consolidator on minute data is rejected inInitialize.QuoteDerivedTradeBarTests: mid-point collapse, volume get/set throw, clones keep the type, consolidation keeps bars volume-less.SubscriptionManagerTests: adapter data flow and removal, Python adapted consolidator add/remove, adapter equality, comparer matching both ways, period validation cases, null-symbol message, mismatch suggestion.AlgorithmIndicatorsTests: calendar registration in C# and Python,MassIndexon a quote-only feed updates,OnBalanceVolumeon a quote-only feed throws on the first bar.PythonIndicatorTests: updated messages.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>