{"record":{"id":"00e9c670de11afb0","repo":"HKUDS/Vibe-Trading","slug":"no-asset-has-both-a-finite-value-and-a-positive-ma","errorCode":null,"errorMessage":"no asset has both a finite value and a positive market cap","messagePattern":"no asset has both a finite value and a positive market cap","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/factormodel.py","lineNumber":296,"sourceCode":"    if winsorise > 0:\n        lower, upper = finite.quantile(winsorise), finite.quantile(1.0 - winsorise)\n        clipped = series.clip(lower=lower, upper=upper)\n    else:\n        clipped = series\n\n    if market_caps is None:\n        centre = float(clipped.dropna().mean())\n    else:\n        caps = pd.Series(market_caps, dtype=float)\n        missing = series.index.difference(caps.index)\n        if len(missing):\n            raise ValueError(\n                f\"market_caps is missing {len(missing)} asset(s) present in values\"\n            )\n        aligned_caps = caps.reindex(clipped.index)\n        usable = clipped.notna() & aligned_caps.notna() & (aligned_caps > 0)\n        if not usable.any():\n            raise ValueError(\"no asset has both a finite value and a positive market cap\")\n        weights = aligned_caps[usable]\n        centre = float((clipped[usable] * weights).sum() / weights.sum())\n\n    spread = float(clipped.dropna().std(ddof=1))\n    if not np.isfinite(spread) or spread <= 0.0:\n        raise ValueError(\n            \"the characteristic has no cross-sectional variation, so a z-score \"\n            \"would divide by zero\"\n        )\n    return (clipped - centre) / spread\n\n\ndef build_style_exposures(\n    characteristics: pd.DataFrame,\n    market_caps: pd.Series | None = None,\n    definitions: Mapping[str, Mapping[str, int]] = STYLE_FACTOR_DEFINITIONS,\n    winsorise: float = DEFAULT_WINSORISE,\n) -> tuple[pd.DataFrame, dict[str, int]]:","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/factormodel.py#L278-L314","documentation":"With market_caps given, standardise_exposures computes a cap-weighted mean as the centring constant; if no asset simultaneously has a finite characteristic value and a strictly positive cap, that weighted mean is undefined and this error is raised.","triggerScenarios":"All caps NaN/zero for the assets with finite values — e.g. caps expressed in thousands so tiny values round to zero, or NaN characteristic exactly where caps exist, producing an empty usable set.","commonSituations":"Unit mismatch (caps in millions vs raw counts with zeros), stale caps files with NaNs, or characteristics whose coverage does not overlap the capped universe at all.","solutions":["Inspect the usable mask: usable = values.notna() & caps.notna() & (caps > 0); print(usable.sum()).","Fix cap units/zeros (floor small caps at a positive epsilon) or repair NaN coverage so the intersection is non-empty."],"exampleFix":"# before\nz = standardise_exposures(values, market_caps=caps)  # caps has zeros\n# after\ncaps = caps.where(caps > 0, 1.0)  # floor zero/NaN caps at 1 (equal weight)\nz = standardise_exposures(values, market_caps=caps)","handlingStrategy":"validation","validationCode":"usable = values.notna() & caps.notna() & (caps > 0)\nassert usable.any()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Floor zero caps at a small positive value or equal-weight.","Validate cap units before ingestion."],"tags":["factormodel","market-caps","empty-input"],"backgroundTag":"empty-collection-argument","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}