{"record":{"id":"848dea8101e794d4","repo":"QuantConnect/Lean","slug":"maximumsectorexposureriskmanagementmodel-on-securi","errorCode":null,"errorMessage":"MaximumSectorExposureRiskManagementModel.on_securities_changed: Please select a portfolio selection model that selects securities with fundamental data.","messagePattern":"MaximumSectorExposureRiskManagementModel\\.on_securities_changed: Please select a portfolio selection model that selects securities with fundamental data\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Algorithm.Framework/Risk/MaximumSectorExposureRiskManagementModel.py","lineNumber":89,"sourceCode":"            if ratio > 1:\n                for symbol, quantity in quantities.items():\n                    if quantity != 0:\n                        risk_targets.append(PortfolioTarget(symbol, float(quantity) / ratio))\n\n        return risk_targets\n\n    def on_securities_changed(self, algorithm, changes):\n        '''Event fired each time the we add/remove securities from the data feed\n        Args:\n            algorithm: The algorithm instance that experienced the change in securities\n            changes: The security additions and removals from the algorithm'''\n        any_fundamental_data = any([\n            kvp.value.fundamentals is not None and\n            kvp.value.fundamentals.has_fundamental_data for kvp in algorithm.active_securities\n            ])\n\n        if not any_fundamental_data:\n            raise Exception(\"MaximumSectorExposureRiskManagementModel.on_securities_changed: Please select a portfolio selection model that selects securities with fundamental data.\")\n","sourceCodeStart":71,"sourceCodeEnd":90,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Framework/Risk/MaximumSectorExposureRiskManagementModel.py#L71-L90","documentation":"MaximumSectorExposureRiskManagementModel.on_securities_changed requires every managed security to carry fundamental data (specifically sector) so it can group positions by sector. If no security in algorithm.active_securities has fundamentals.has_fundamental_data, it cannot attribute exposure by sector and raises a generic Exception.","triggerScenarios":"The algorithm's universe/portfolio selection picked securities without fundamental data (e.g., a coarse-only universe, an options/futures universe, or custom data), so the any(...) check over active_securities is false when securities change.","commonSituations":"Using CoarseFundamentalUniverseSelectionModel or a manual AddSecurity set without fine fundamentals; selecting options/crypto/forex; or a fine universe whose filter stripped out all fundamental-bearing symbols.","solutions":["Use a portfolio/universe selection model that yields securities with fundamentals — e.g., FineFundamentalUniverseSelectionModel or FundamentalUniverseSelectionModel.","If using manual AddEquity, ensure the securities are fundamental-eligible (US equities) and that fine data is enabled.","Avoid attaching this risk model to option/future/crypto-only algorithms; pick a risk model that doesn't need sector data."],"exampleFix":"# before\nself.set_universe_selection(CoarseFundamentalUniverseSelectionModel(self.coarse))\nself.add_risk_management(MaximumSectorExposureRiskManagementModel(0.20))  # no fundamentals -> raises\n\n# after\nself.set_universe_selection(FineFundamentalUniverseSelectionModel(self.fine))\nself.add_risk_management(MaximumSectorExposureRiskManagementModel(0.20))","handlingStrategy":"validation","validationCode":"# Only attach this risk model when the universe yields fundamental data\nhas_fundamentals = any(\n    s.fundamentals is not None and s.fundamentals.has_fundamental_data\n    for s in algorithm.active_securities.Values\n)\nif has_fundamentals:\n    self.add_risk_management(MaximumSectorExposureRiskManagementModel(0.20))","typeGuard":"def universe_has_fundamentals(algorithm) -> bool:\n    return any(\n        kvp.value.fundamentals is not None and kvp.value.fundamentals.has_fundamental_data\n        for kvp in algorithm.active_securities\n    )","tryCatchPattern":null,"preventionTips":["Pair sector-based risk models with a fundamental/fine universe selection model.","Don't use sector risk models on options, futures, crypto, or coarse-only equity universes.","If fundamentals may be absent, choose a price/volatility-based risk model instead."],"tags":["risk-management","fundamentals","universe-selection"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}