Fail loudly on canonical continuous future orders, add Future.Canonical and mapped-contract guidance - #9681
Draft
jhonabreul wants to merge 1 commit into
Conversation
…nical - PortfolioTarget.Percent rejects canonical future symbols with an instructive error, so CalculateOrderQuantity returns 0 with a clear message and SetHoldings no longer submits doomed orders - Non-tradable order rejections for canonical symbols now point to Future.Mapped and explain it is not set until after Initialize - Order methods throw a named ArgumentNullException for null symbols (common case: ordering Future.Mapped from Initialize) instead of NRE - Add Future.Canonical as an alias of Symbol.Canonical - Warn once when a future stop/limit/trigger price deviates more than 10% from the contract market price while the continuous subscription uses a non-Raw data normalization mode
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
Ordering the canonical continuous futures symbol fails silently:
CalculateOrderQuantity(canonical, 1.0)returns a plausible quantity, andSetHoldings(canonical, 0.5)submits an order rejected with only:Related traps:
Future.Mappedis null duringInitialize, so passing it to order methods dies with a bare NRE; stop/limit prices computed from adjusted continuous prices sit far from the mapped contract's raw prices.Cause: nothing on the canonical order path names the problem or points to
Future.Mapped, and the buying power path computes quantities for a security that can never trade.The fix:
PortfolioTarget.Percentrejects canonical future symbols with an instructive error and returns null, soCalculateOrderQuantityreturns 0 andSetHoldingsno longer submits doomed orders. Restricted to futures.QCAlgorithm.PreOrderChecksImplnon-tradable rejection now usesMessages.QCAlgorithm.CanonicalSymbolNotTradablefor canonical symbols, telling the user to tradeFuture.Mapped. Messages are language-aware for Python.QCAlgorithm.GetSecurityForOrderthrowsArgumentNullExceptionwith the same guidance for null symbols instead of an opaque NRE. Covers all order helpers.Future.Canonicaladded as an alias ofSymbol.Canonical(future.canonicalin Python);Future.MappedXML docs now state it is null until the first universe selection.PreOrderChecksImplwarns once when a future order's stop/limit/trigger price deviates more than 10% from market price while the continuous subscription uses a non-RawDataNormalizationMode.SignalExportTargetTestsfuture cases switched from holdings on the canonical security (now rejected) to a real ES contract.Not changed:
slice.Barslookups with the canonical symbol already resolve the continuous bar (asserted in the regression algorithm).Related Issue
N/A
Note: sibling PR #9675 covers the null-symbol NRE in
AddConsolidator/GetSubscription; this PR covers the order path.Motivation and Context
The silent canonical-order failure is especially costly to debug. Loud, named errors close the worst silent failure mode in futures algorithms.
Requires Documentation Change
No — error messages and a new property alias.
How Has This Been Tested?
ContinuousFutureCanonicalOrdersRegressionAlgorithm(C# + Python): asserts the new errors and null/zero results end-to-end, that canonical bars still resolve, and that the mapped contract trades normally.AlgorithmTradingTestscovering canonical order rejection, zero order quantity, null-symbol guidance, and the price-deviation warning (fires once for non-Raw, never for Raw or near-market prices).PortfolioTargetTests.PercentReturnsNullForCanonicalFutureSymbol.AlgorithmTradingTests+ allFramework.Portfoliotests: 813 passed, 0 failed.ContinuousFuture*/FuturesFramework*regression algorithms: all passed.Types of changes
Breaking only narrowly:
PortfolioTarget.Percent/CalculateOrderQuantitynow return null/0 with an error for canonical future symbols instead of a quantity that could not be traded anyway.Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>