{"record":{"id":"2413733be011aa6b","repo":"HKUDS/Vibe-Trading","slug":"exposures-contains-non-finite-values","errorCode":null,"errorMessage":"exposures contains non-finite values","messagePattern":"exposures contains non-finite values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/factormodel.py","lineNumber":641,"sourceCode":"    Returns:\n        :class:`FactorRiskDecomposition` containing total/factor/specific\n        variances, volatilities, marginal contributions to risk (MCR), and\n        percentage contributions to risk (PCR) per factor and per asset.\n\n    Raises:\n        ValueError: If weights or matrices are empty, contain non-finite values,\n            or share no common assets or factors.\n    \"\"\"\n    w_series = pd.Series(portfolio_weights, dtype=float)\n    if w_series.empty:\n        raise ValueError(\"portfolio_weights cannot be empty\")\n    if not np.isfinite(w_series.values).all():\n        raise ValueError(\"portfolio_weights contains non-finite values\")\n\n    if not isinstance(exposures, pd.DataFrame) or exposures.empty:\n        raise ValueError(\"exposures must be a non-empty DataFrame\")\n    if not np.isfinite(exposures.values).all():\n        raise ValueError(\"exposures contains non-finite values\")\n\n    if not isinstance(factor_cov, pd.DataFrame) or factor_cov.empty:\n        raise ValueError(\"factor_cov must be a non-empty DataFrame\")\n    if not np.isfinite(factor_cov.values).all():\n        raise ValueError(\"factor_cov contains non-finite values\")\n\n    # Align assets\n    assets = w_series.index.intersection(exposures.index)\n    if assets.empty:\n        raise ValueError(\n            f\"No matching assets between weights ({sorted(w_series.index)}) and exposures ({sorted(exposures.index)})\"\n        )\n\n    unmatched_weight = float(w_series.drop(index=assets, errors=\"ignore\").abs().sum())\n    w = w_series.loc[assets]\n    X = exposures.loc[assets]\n\n    # Align factors","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/factormodel.py#L623-L659","documentation":"The exposures matrix must contain only finite numbers; a NaN/inf entry would propagate into x_p = Xᵀw and corrupt every risk number, so the function validates up front.","triggerScenarios":"A NaN in the asset-factor matrix from a partial data join, or inf from a bad z-score division by zero std.","commonSituations":"Cross-sectional standardization with zero-variance factors; sparse vendor data with missing cells not filled.","solutions":["Locate bad cells: exposures[~np.isfinite(exposures.values)] / exposures.mask(~np.isfinite(exposures))","Fill NaNs with 0 exposure or drop the affected assets/factors","Fix the standardizer to guard zero std before dividing"],"exampleFix":"# before\nrisk = factor_risk_decomposition(w, X, F)\n# after\nX = X.fillna(0.0).replace([np.inf, -np.inf], 0.0)\nrisk = factor_risk_decomposition(w, X, F)","handlingStrategy":"validation","validationCode":"assert np.isfinite(exposures.values).all()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fill/validate NaNs at ingest (X.fillna(0))","Guard zero-std in standardizers before dividing"],"tags":["quantlib","factormodel","nan","inf","validation"],"backgroundTag":"non-finite-values","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}