Improve consolidator registration ergonomics: quote-to-trade bar adaptation, registration-time period validation, calendar periods in RegisterIndicator - #9675
Draft
jhonabreul wants to merge 1 commit 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
11 tasks
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 in ways that are avoidable or needlessly late: type mismatch rejections the engine could adapt, period validation deferred to the first data point (potentially months into a backtest), calendar periods accepted by
Consolidate()but notRegisterIndicator, and an NRE on null symbols.The change:
SubscriptionManager.AddConsolidatoradapts trade bar consolidators to quote-only feeds: a newQuoteBarToTradeBarAdaptercollapses eachQuoteBarinto a mid-point, zero-volumeTradeBar. Removal by the user-held consolidator still works.QCAlgorithm.RegisterIndicator<T>does the same at the indicator layer (e.g.self.obv(symbol, Resolution.HOUR)on a cfd).Initializewith an actionable message instead of at the first bar.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) throws anArgumentNullExceptionexplaining the likely cause instead of an NRE.Deferred: single-parameter Python
data_consolidatedhandlers (interop-layer concern), calendar overloads on every indicator helper, and quote-feed adaptation of the C#Consolidate(symbol, period, Action<TradeBar>)overloads.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.How Has This Been Tested?
ConsolidatorAutoAdaptationRegressionAlgorithm(C# + Python): adaptation on EURUSD, weekly RSI via calendar rule, registration-time period rejection.SubscriptionManagerTests: adapter data flow and removal, period validation cases, null-symbol message, mismatch suggestion.AlgorithmIndicatorsTestsandPythonIndicatorTests: calendar registration (C# and Python), adapted indicators, updated messages.Tests.Common.Data(905 passed), affected fixtures (448 passed), 60 consolidator/indicator regression algorithms passed.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>