Skip to content

Fall back from open interest mapping for KRX futures and warn on unavailable mapping modes - #9831

Open
jhonabreul wants to merge 7 commits into
QuantConnect:masterfrom
jhonabreul:bug-9764-krx-open-interest-mapping-fallback
Open

jhonabreul wants to merge 7 commits into
QuantConnect:masterfrom
jhonabreul:bug-9764-krx-open-interest-mapping-fallback

Conversation

@jhonabreul

@jhonabreul jhonabreul commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Continuous futures on KRX (e.g. KM) get no history and no data with default settings. Passing OpenInterest explicitly on EUREX, HKFE, ICE or KRX, or adding the same future twice with different settings, also fails with no feedback.

Cause: these markets have no open interest mapping data, and the LastTradingDay fallback only covered EUREX, HKFE and ICE when no mode was passed. The KRX market was added in #9585 but never added to that fallback.

The fix:

  • Extensions.GetUniverseMappingModeOrDefault now also falls back from OpenInterest/OpenInterestAnnual to LastTradingDay for KRX.
  • The market check moves to a new DataMappingMode.IsAvailableForFutureMarket(market) extension.
  • AddFuture and History() fall back to the market default for an unsupported mapping mode, whether it is the default or passed explicitly.
  • The fallback warns once per market, shared by AddFuture and History().
  • Only continuous futures fall back: contracts and chain history are not mapped, so they keep the mode as passed and don't warn.
  • A second AddFuture with a different mapping mode, normalization mode or contract depth offset keeps the first settings and warns once.
  • The second call is ignored because these settings are not part of the future Symbol, so both calls resolve to the same /ES.
  • The mapping mode is compared after the fallback, so re-adding FESX with OpenInterest does not warn.
  • In Initialize, the warning says to add the future once. After Initialize, it says to remove it with RemoveSecurity() and add it again.

Examples:

KRX future with default settings now falls back:

AddFuture("KM", market: Market.KRX);
// Warning: OpenInterest data mapping mode is not available for KRX futures, using LastTradingDay instead.

Explicit unsupported mapping mode in AddFuture now falls back:

AddFuture("FESX", market: Market.EUREX, dataMappingMode: DataMappingMode.OpenInterest);
// Warning: OpenInterest data mapping mode is not available for EUREX futures, using LastTradingDay instead.

Explicit unsupported mapping mode in History() now falls back:

History(fesx.Symbol, 10, Resolution.Daily, dataMappingMode: DataMappingMode.OpenInterest);
// Warning: OpenInterest data mapping mode is not available for EUREX futures, using LastTradingDay instead.

Re-adding a future with different settings in Initialize:

AddFuture("ES", dataMappingMode: DataMappingMode.OpenInterest);
AddFuture("ES", dataMappingMode: DataMappingMode.LastTradingDay);
// Warning: /ES already added, ignoring data mapping mode LastTradingDay. Add it once, or remove and re-add it after Initialize.

Re-adding a future with different settings after Initialize (e.g. in OnData):

AddFuture("ES", dataMappingMode: DataMappingMode.LastTradingDay);
// Warning: /ES already added, ignoring data mapping mode LastTradingDay. Remove it first to change its settings.

Related Issue

Closes #9764

Motivation and Context

The KOSPI 200 futures added in #9585 get no data with default settings. The other cases return empty data with no hint why.

Requires Documentation Change

No.

How Has This Been Tested?

  • ExtensionsTests.GetUniverseMappingModeOrDefault: OpenInterest falls back on KRX/EUREX/HKFE/ICE and not on CME.
  • AlgorithmAddSecurityTests.AddFutureFallsBackFromUnavailableDataMappingMode: default and explicit OpenInterest fall back on KRX/EUREX with the exact warning; supported modes are kept.
  • AlgorithmAddSecurityTests.AddFutureDataMappingModeFallbackWarnsOncePerMarket: one fallback warning per market.
  • AlgorithmAddSecurityTests.AddFutureFallsBackToUniverseSettingsDataMappingMode: fallback uses a supported UniverseSettings.DataMappingMode.
  • AlgorithmHistoryTests.HistoryWithExplicitUnavailableDataMappingModeFallsBackToMarketDefault: explicit OpenInterest requests use LastTradingDay, even if the future was added with another mode, and warn once.
  • AlgorithmHistoryTests.HistoryWithoutDataMappingModeFallsBackForFutureNotAdded: default history of a future not added falls back and warns once.
  • AlgorithmHistoryTests.HistoryWithExplicitAvailableDataMappingModeKeepsIt: a supported explicit mode is kept with no warning.
  • AlgorithmHistoryTests.HistoryWithExplicitUnavailableDataMappingModeDoesNotFallBackForContractsOrChains: contract and chain requests keep OpenInterest and don't warn.
  • AlgorithmAddSecurityTests.AddFutureAgain*: conflicting re-adds keep the first settings and warn once with the right text; matching re-adds don't warn.
  • AlgorithmAddSecurityTests.AddFutureAfterRemovingItAppliesNewSettings: removing and re-adding applies the new mapping mode.
  • FutureDataMappingModeFallbackRegressionAlgorithm (C#/Python, FESX data): explicit OpenInterest maps to the June contract via the fallback, explicit OpenInterest history matches default history, and the after-Initialize re-add warning is sent. Fails on master.
  • Cloud backtest: FESX, FDAX, HSI and KM returned 0 rows with OpenInterest and 1300 rows with LastTradingDay.
  • AlgorithmAddSecurityTests, AlgorithmAddDataTests, AlgorithmHistoryTests and ExtensionsTests suites: 11620 passed, 0 failed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

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.

Explicit OpenInterest DataMappingMode on EUREX/HKFE/KRX futures leaves the continuous contract unmapped and History() empty

1 participant