{"record":{"id":"a4162ad8e5039b68","repo":"QuantConnect/Lean","slug":"futurechainsymbolselector-must-return-future-symbo","errorCode":null,"errorMessage":"futureChainSymbolSelector must return future symbols.","messagePattern":"futureChainSymbolSelector must return future symbols\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Algorithm.Framework/Selection/FutureUniverseSelectionModel.py","lineNumber":50,"sourceCode":"        self.future_chain_symbol_selector = futureChainSymbolSelector\n        self.universe_settings = universeSettings\n\n    def get_next_refresh_time_utc(self):\n        '''Gets the next time the framework should invoke the `CreateUniverses` method to refresh the set of universes.'''\n        return self.next_refresh_time_utc\n\n    def create_universes(self, algorithm: QCAlgorithm) -> list[Universe]:\n        '''Creates a new fundamental universe using this class's selection functions\n        Args:\n            algorithm: The algorithm instance to create universes for\n        Returns:\n            The universe defined by this model'''\n        self.next_refresh_time_utc = algorithm.utc_time + self.refresh_interval\n\n        unique_symbols = set()\n        for future_symbol in self.future_chain_symbol_selector(algorithm.utc_time):\n            if future_symbol.SecurityType != SecurityType.FUTURE:\n                raise ValueError(\"futureChainSymbolSelector must return future symbols.\")\n\n            # prevent creating duplicate future chains -- one per symbol\n            if future_symbol not in unique_symbols:\n                unique_symbols.add(future_symbol)\n                selection = self.filter\n                if hasattr(self, \"Filter\") and callable(self.Filter):\n                    selection = self.Filter\n                for universe in Extensions.create_future_chain(algorithm, future_symbol, selection, self.universe_settings):\n                    yield universe\n\n    def filter(self, filter):\n        '''Defines the future chain universe filter'''\n        # NOP\n        return filter\n","sourceCodeStart":32,"sourceCodeEnd":65,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Framework/Selection/FutureUniverseSelectionModel.py#L32-L65","documentation":"FutureUniverseSelectionModel.create_universes() iterates the user-supplied future_chain_symbol_selector and builds a FutureChain per returned symbol. Each returned symbol MUST be of SecurityType.Future; any other security type raises ValueError because the model can only construct future chains for future underlyings.","triggerScenarios":"The future_chain_symbol_selector callback returns a Symbol whose SecurityType is not SecurityType.FUTURE (e.g., an equity, option, index, or forex symbol slipped in).","commonSituations":"Using Symbol.Create or Symbol.CreateFuture incorrectly (wrong security type), returning underlying equity symbols instead of future canonicals, or a typo in the canonical symbol string.","solutions":["Ensure the selector returns only future symbols, e.g. Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME) or the QuantConnect future canonical.","Validate each returned symbol's security_type == SecurityType.FUTURE before returning it from the selector.","Double-check the Symbol.Create call's security-type argument — it's the second positional parameter."],"exampleFix":"# before\ndef selector(utc):\n    return [Symbol.Create('SPY', SecurityType.Equity, Market.USA)]  # wrong type -> raises\n\n# after\ndef selector(utc):\n    return [Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME)]","handlingStrategy":"validation","validationCode":"def future_selector(utc):\n    syms = my_selector(utc)\n    bad = [s for s in syms if s.security_type != SecurityType.FUTURE]\n    if bad:\n        raise ValueError(f'Non-future symbols returned: {bad}')\n    return syms","typeGuard":"def all_are_futures(symbols) -> bool:\n    return all(s.security_type == SecurityType.FUTURE for s in symbols)","tryCatchPattern":null,"preventionTips":["Always pass SecurityType.Future as the second arg to Symbol.Create for future canonicals.","Return canonical future symbols, not underlying equities or indices."],"tags":["universe-selection","futures","symbol","validation"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}