{"record":{"id":"cd6428e97f6b915b","repo":"HKUDS/Vibe-Trading","slug":"cross-sectional-regression-needs-at-least-min-cro","errorCode":null,"errorMessage":"cross-sectional regression needs at least {MIN_CROSS_SECTION} assets with both a return and full exposures, got {len(common)}","messagePattern":"cross-sectional regression needs at least (.+?) assets with both a return and full exposures, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/factormodel.py","lineNumber":408,"sourceCode":"        returns: Asset returns for the date being explained, indexed by asset.\n        exposures: Exposure matrix from the *previous* date, rows indexed by\n            asset. Using the same date's exposures would be a look-ahead: the\n            characteristic and the return would share information.\n        market_caps: Market capitalisation by asset for the regression weights.\n            When None the regression is unweighted.\n        date: Label recorded on the result. Purely informational.\n\n    Returns:\n        A :class:`FactorReturnFit`.\n\n    Raises:\n        ValueError: If fewer than :data:`MIN_CROSS_SECTION` assets are common to\n            the inputs, if the design matrix has more columns than rows, or if\n            the exposures are perfectly collinear.\n    \"\"\"\n    common = returns.dropna().index.intersection(exposures.dropna(how=\"any\").index)\n    if len(common) < MIN_CROSS_SECTION:\n        raise ValueError(\n            f\"cross-sectional regression needs at least {MIN_CROSS_SECTION} assets \"\n            f\"with both a return and full exposures, got {len(common)}\"\n        )\n\n    y = returns.loc[common].to_numpy(dtype=float)\n    factor_names = list(exposures.columns)\n    design = np.column_stack(\n        [np.ones(len(common)), exposures.loc[common].to_numpy(dtype=float)]\n    )\n    names = [MARKET_FACTOR, *factor_names]\n\n    if design.shape[1] > design.shape[0]:\n        raise ValueError(\n            f\"{design.shape[1]} regressors but only {design.shape[0]} assets; \"\n            \"the fit would be exactly determined and meaningless\"\n        )\n\n    if market_caps is None:","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/factormodel.py#L390-L426","documentation":"cross_sectional_factor_returns regresses returns on exposures per date; it requires at least MIN_CROSS_SECTION assets that simultaneously have a non-NaN return and a complete (no NaN in any column) exposure row. Below that floor the factor return estimates are too noisy, so it refuses.","triggerScenarios":"An inner join of returns.dropna() and exposures.dropna(how='any') shrinking below the minimum — e.g. one characteristic mostly NaN wipes out complete rows even though returns are fine.","commonSituations":"Sparse characteristics (analyst estimates coverage), small pilot universes, exposures built with fillna(0) removed by a strictness change, or a date where many tickers lack returns.","solutions":["Diagnose the intersection: common = returns.dropna().index.intersection(exposures.dropna(how='any').index); print(len(common)).","Fill or drop sparse exposure columns (build_style_exposures already fills missing cells with 0 and counts them), or restrict the universe to names with full data."],"exampleFix":"# before\nfr = cross_sectional_factor_returns(returns, exposures_with_nans)\n# after\nexposures_filled = exposures_with_nans.fillna(0.0)\nfr = cross_sectional_factor_returns(returns, exposures_filled)","handlingStrategy":"validation","validationCode":"common = returns.dropna().index.intersection(exposures.dropna(how=\"any\").index)\nassert len(common) >= MIN_CROSS_SECTION, len(common)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fill missing exposure cells with 0 (and track counts) before regressing.","Monitor cross-section size per date; skip thin dates."],"tags":["factormodel","cross-section","minimum-sample"],"backgroundTag":"insufficient-data-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}