{"record":{"id":"1a4b8ec569155fdb","repo":"HKUDS/Vibe-Trading","slug":"waccresult-wacc-self-wacc-r-does-not-match-the-w","errorCode":null,"errorMessage":"WACCResult.wacc={self.wacc!r} does not match the weighted blend {expected!r} of cost_of_equity and cost_of_debt_after_tax","messagePattern":"WACCResult\\.wacc=(.+?) does not match the weighted blend (.+?) of cost_of_equity and cost_of_debt_after_tax","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/dcf.py","lineNumber":366,"sourceCode":"    debt_weight: float\n    wacc: float\n\n    def __post_init__(self) -> None:\n        \"\"\"Re-check the blend arithmetic and the weight identity.\n\n        Raises:\n            ValueError: If the weights do not sum to 1, or ``wacc`` is not the\n                stated weighted blend of the two costs of capital.\n        \"\"\"\n        _validate_weights(self.equity_weight, self.debt_weight, model=\"WACCResult\")\n        expected = (\n            self.equity_weight * self.cost_of_equity\n            + self.debt_weight * self.cost_of_debt_after_tax\n        )\n        if not math.isclose(\n            self.wacc, expected, rel_tol=_RECONCILIATION_TOLERANCE, abs_tol=1e-12\n        ):\n            raise ValueError(\n                f\"WACCResult.wacc={self.wacc!r} does not match the weighted \"\n                f\"blend {expected!r} of cost_of_equity and cost_of_debt_after_tax\"\n            )\n\n\ndef wacc(\n    *,\n    risk_free_rate: float,\n    beta: float,\n    equity_risk_premium: float,\n    pretax_cost_of_debt: float,\n    tax_rate: float,\n    capital_structure_basis: str,\n    market_value_of_equity: float | None = None,\n    market_value_of_debt: float | None = None,\n    target_equity_weight: float | None = None,\n    target_debt_weight: float | None = None,\n    size_premium: float = 0.0,","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/dcf.py#L348-L384","documentation":"WACCResult.__post_init__ recomputes equity_weight*cost_of_equity + debt_weight*cost_of_debt_after_tax and raises ValueError if the stored wacc field does not match within tolerance. It enforces internal consistency of the result object (no silently inconsistent dataclass).","triggerScenarios":"Manually constructing WACCResult(wacc=0.10, equity_weight=0.5, cost_of_equity=0.12, debt_weight=0.5, cost_of_debt_after_tax=0.04) where the blend is 0.08, not 0.10; mutating fields after construction is similarly caught on revalidation.","commonSituations":"Building the result object by hand in tests or adapters instead of calling wacc(); copy-paste of numbers from a stale model run.","solutions":["Construct WACCResult via the public wacc() function rather than manually","If constructing manually, compute wacc = e_w*Ke + d_w*Kd_at and pass that exact value","Recompute the blend after any field change instead of editing wacc in isolation"],"exampleFix":"# before\nWACCResult(wacc=0.10, equity_weight=.5, cost_of_equity=.12, debt_weight=.5, cost_of_debt_after_tax=.04)\n\n# after\nWACCResult(wacc=.5*.12 + .5*.04, equity_weight=.5, cost_of_equity=.12, debt_weight=.5, cost_of_debt_after_tax=.04)","handlingStrategy":"validation","validationCode":"w = equity_weight * cost_of_equity + debt_weight * cost_of_debt_after_tax\nresult = WACCResult(wacc=w, equity_weight=equity_weight, ...)","typeGuard":null,"tryCatchPattern":"try:\n    WACCResult(...)\nexcept ValueError as e:\n    raise AssertionError(f'inconsistent WACC inputs: {e}') from e","preventionTips":["Always build WACCResult via wacc()","Compute wacc from the same numbers stored in the object","Don't mutate result fields independently"],"tags":["valuation","wacc","dataclass-invariants","reconciliation"],"backgroundTag":"derived-field-mismatch","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}