{"record":{"id":"8b2b83febbcdd530","repo":"HKUDS/Vibe-Trading","slug":"wacc-market-value-of-equity-plus-debt-is-zero-d","errorCode":null,"errorMessage":"wacc: market value of equity plus debt is zero (D + E = 0); capital-structure weights are undefined","messagePattern":"wacc: market value of equity plus debt is zero \\(D \\+ E = 0\\); capital-structure weights are undefined","errorType":"validation","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/dcf.py","lineNumber":458,"sourceCode":"        missing = [\n            name\n            for name, value in (\n                (\"market_value_of_equity\", market_value_of_equity),\n                (\"market_value_of_debt\", market_value_of_debt),\n            )\n            if value is None\n        ]\n        if missing:\n            raise MissingInputError(missing, \"wacc\")\n        equity_mv = _require_nonnegative(\n            market_value_of_equity, \"market_value_of_equity\", \"wacc\"\n        )\n        debt_mv = _require_nonnegative(\n            market_value_of_debt, \"market_value_of_debt\", \"wacc\"\n        )\n        total_mv = equity_mv + debt_mv\n        if total_mv <= 0.0:\n            raise ValuationError(\n                \"wacc: market value of equity plus debt is zero (D + E = 0); \"\n                \"capital-structure weights are undefined\"\n            )\n        equity_weight = equity_mv / total_mv\n        debt_weight = debt_mv / total_mv\n    else:\n        missing = [\n            name\n            for name, value in (\n                (\"target_equity_weight\", target_equity_weight),\n                (\"target_debt_weight\", target_debt_weight),\n            )\n            if value is None\n        ]\n        if missing:\n            raise MissingInputError(missing, \"wacc\")\n        equity_weight = _require_finite(\n            target_equity_weight, \"target_equity_weight\", \"wacc\"","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/dcf.py#L440-L476","documentation":"With basis 'current', wacc() computes weights as E/(D+E) and D/(D+E); if both market values are zero (or sum to <= 0, which given non-negative validation means both zero), the weights are mathematically undefined and a ValuationError is raised instead of returning NaN.","triggerScenarios":"wacc(capital_structure_basis='current', market_value_of_equity=0, market_value_of_debt=0) — e.g. a pre-IPO shell entity or a placeholder row of zeros in a dataset.","commonSituations":"Screening universes containing shell/holding companies with zero market cap; default-zero rows from joins where the market-data fetch failed.","solutions":["Skip entities with zero total market value or handle them in a separate branch","Use capital_structure_basis='target' with target weights for such entities","Pre-filter input rows: if equity_mv + debt_mv <= 0, exclude before calling wacc"],"exampleFix":"# before\nfor row in rows:\n    wacc(..., market_value_of_equity=row['e_mv'], market_value_of_debt=row['d_mv'])\n\n# after\nfor row in rows:\n    if row['e_mv'] + row['d_mv'] <= 0:\n        continue\n    wacc(..., market_value_of_equity=row['e_mv'], market_value_of_debt=row['d_mv'])","handlingStrategy":"validation","validationCode":"if (e_mv or 0) + (d_mv or 0) <= 0:\n    skip(ticker, reason='zero market cap')\nwacc(..., market_value_of_equity=e_mv, market_value_of_debt=d_mv)","typeGuard":"def has_positive_total_mv(e_mv: float, d_mv: float) -> bool:\n    return (e_mv + d_mv) > 0","tryCatchPattern":"try:\n    wacc(...)\nexcept ValuationError as e:\n    if 'D + E = 0' in str(e):\n        return wacc(..., capital_structure_basis='target', target_equity_weight=1.0, target_debt_weight=0.0)\n    raise","preventionTips":["Filter zero-market-cap entities upstream","Use target weights for shells/pre-IPO entities","Never substitute 0 for missing market values"],"tags":["valuation","wacc","division-by-zero","degenerate-input"],"backgroundTag":"zero-denominator-guard","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}