{"record":{"id":"0d679fbe1ce7086f","repo":"QuantConnect/Lean","slug":"futureschain-returned-contract-with-no-data","errorCode":null,"errorMessage":"FuturesChain() returned contract with no data.","messagePattern":"FuturesChain\\(\\) returned contract with no data\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/FuturesChainFullDataRegressionAlgorithm.py","lineNumber":35,"sourceCode":"### Regression algorithm illustrating the usage of the <see cref=\"QCAlgorithm.FuturesChain(Symbol, bool)\"/>\n### method to get a future chain.\n### </summary>\nclass FuturesChainFullDataRegressionAlgorithm(QCAlgorithm):\n\n    def initialize(self):\n        self.set_start_date(2013, 10, 7)\n        self.set_end_date(2013, 10, 7)\n\n        future = self.add_future(Futures.Indices.SP_500_E_MINI, Resolution.MINUTE).symbol\n\n        chain = self.futures_chain(future, flatten=True)\n\n        # Demonstration using data frame:\n        df = chain.data_frame\n\n        for index, row in df.iterrows():\n            if row['bidprice'] == 0 and row['askprice'] == 0 and row['volume'] == 0:\n                raise AssertionError(\"FuturesChain() returned contract with no data.\");\n\n        # Get contracts expiring within 6 months, with the latest expiration date, and lowest price\n        contracts = df.loc[(df.expiry <= self.time + timedelta(days=180))]\n        contracts = contracts.sort_values(['expiry', 'lastprice'], ascending=[False, True])\n        self._future_contract = contracts.index[0]\n\n        self.add_future_contract(self._future_contract)\n\n    def on_data(self, data):\n        # Do some trading with the selected contract for sample purposes\n        if not self.portfolio.invested:\n            self.set_holdings(self._future_contract, 0.5)\n        else:\n            self.liquidate()\n","sourceCodeStart":17,"sourceCodeEnd":50,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/FuturesChainFullDataRegressionAlgorithm.py#L17-L50","documentation":"Data-quality assertion in a FuturesChain regression: for every row in the futures_chain(future, flatten=True).data_frame, if bidprice, askprice AND volume are all 0 the test aborts, proving every returned contract has at least some market data.","triggerScenarios":"The chain returning a contract whose data file has no quotes and no trades for the requested bar; a stale or placeholder contract entry with zero data; flatten=True surfacing contracts that have no row-level data.","commonSituations":"Data drop missing quote/trade files for one contract; chain provider returning expired/illiquid contracts with no activity; resolution mismatch so no bar aggregates; data refresh inserting empty rows.","solutions":["Identify which contract (index) has all-zero bid/ask/volume and inspect its data file.","Filter the chain to contracts that actually have data before trading.","Confirm the resolution requested matches the data granularity available.","Re-run the data generator / re-download the affected contract."],"exampleFix":"// before\nfor index, row in df.iterrows():\n    if row['bidprice'] == 0 and row['askprice'] == 0 and row['volume'] == 0:\n        raise AssertionError(\"FuturesChain() returned contract with no data.\")\n// after - filter out empty contracts instead of failing\ndf = df[~((df['bidprice'] == 0) & (df['askprice'] == 0) & (df['volume'] == 0))]","handlingStrategy":"validation","validationCode":"# Filter empty-data contracts before trading\nmask = ~((df['bidprice'] == 0) & (df['askprice'] == 0) & (df['volume'] == 0))\nempty = df[~mask]\nif not empty.empty:\n    self.debug(f\"Contracts with no data: {list(empty.index)}\")\ndf = df[mask]","typeGuard":"def contract_has_data(row) -> bool:\n    return not (row['bidprice'] == 0 and row['askprice'] == 0 and row['volume'] == 0)","tryCatchPattern":null,"preventionTips":["Filter the chain to contracts with non-zero data before selecting.","Match requested resolution to available data granularity.","Inspect data files for contracts reported empty.","Re-download or regenerate data for illiquid contracts."],"tags":["quantconnect","futures","futures-chain","data-quality","data-frame","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}