{"record":{"id":"032da94ae7e862e2","repo":"HKUDS/Vibe-Trading","slug":"model-capital-structure-weights-must-sum-to-1","errorCode":null,"errorMessage":"{model}: capital-structure weights must sum to 1 (within {_RECONCILIATION_TOLERANCE:g}), got equity_weight={equity_weight!r} + debt_weight={debt_weight!r} = {total!r}","messagePattern":"(.+?): capital-structure weights must sum to 1 \\(within (.+?)\\), got equity_weight=(.+?) \\+ debt_weight=(.+?) = (.+?)","errorType":"validation","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/dcf.py","lineNumber":301,"sourceCode":"    \"\"\"Check that a pair of capital-structure weights is usable.\n\n    Args:\n        equity_weight: Proposed ``E / (D + E)``.\n        debt_weight: Proposed ``D / (D + E)``.\n        model: Model name for the error message.\n\n    Raises:\n        ValuationError: If either weight is negative, or if they do not sum to\n            1 within :data:`_RECONCILIATION_TOLERANCE`.\n    \"\"\"\n    if equity_weight < 0.0 or debt_weight < 0.0:\n        raise ValuationError(\n            f\"{model}: capital-structure weights must be non-negative, got \"\n            f\"equity_weight={equity_weight!r} debt_weight={debt_weight!r}\"\n        )\n    total = equity_weight + debt_weight\n    if abs(total - 1.0) > _RECONCILIATION_TOLERANCE:\n        raise ValuationError(\n            f\"{model}: capital-structure weights must sum to 1 (within \"\n            f\"{_RECONCILIATION_TOLERANCE:g}), got equity_weight={equity_weight!r} \"\n            f\"+ debt_weight={debt_weight!r} = {total!r}\"\n        )\n\n\n# ---------------------------------------------------------------------------\n# WACC\n# ---------------------------------------------------------------------------\n\n\n@dataclass(frozen=True)\nclass WACCResult:\n    \"\"\"The WACC build, with every component that fed it kept visible.\n\n    Attributes:\n        risk_free_rate: ``rf`` used in CAPM.\n        beta: Levered beta used in CAPM.","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/dcf.py#L283-L319","documentation":"Raised by _validate_weights when equity_weight + debt_weight deviates from 1 by more than _RECONCILIATION_TOLERANCE. The two weights must reconcile to a complete capital structure.","triggerScenarios":"wacc(..., target_equity_weight=0.6, target_debt_weight=0.3) (sums to 0.9); entering weights as percentages (60 + 40 = 100) instead of fractions.","commonSituations":"Spreadsheet weights in percent not divided by 100; rounding weights independently so they no longer sum to 1; updating one weight and forgetting the other.","solutions":["Enter weights as fractions summing to exactly 1 (0.65/0.35)","If using percentages, divide both by 100 (or by their sum) before the call","When rounding for display, renormalize: w_i / (w_e + w_d) before passing"],"exampleFix":"# before\nwacc(..., target_equity_weight=60, target_debt_weight=40)\n\n# after\nwacc(..., target_equity_weight=0.60, target_debt_weight=0.40)","handlingStrategy":"validation","validationCode":"total = target_equity_weight + target_debt_weight\nif abs(total - 1.0) > 1e-9:\n    target_equity_weight /= total\n    target_debt_weight /= total  # renormalize\nwacc(..., target_equity_weight=target_equity_weight, target_debt_weight=target_debt_weight)","typeGuard":"def sums_to_one(e: float, d: float, tol: float = 1e-9) -> bool:\n    return abs(e + d - 1.0) <= tol","tryCatchPattern":"try:\n    wacc(...)\nexcept ValuationError as e:\n    if 'sum to 1' in str(e):\n        return wacc(..., target_equity_weight=e_w/(e_w+d_w), target_debt_weight=d_w/(e_w+d_w))\n    raise","preventionTips":["Store weights as fractions, not percentages","Renormalize after rounding","Keep the weight pair in one config object so they change together"],"tags":["valuation","wacc","weights","normalization"],"backgroundTag":"weights-must-sum-to-one","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}