HKUDS/Vibe-Trading · error · ValueError

WACCResult.wacc={self.wacc!r} does not match the weighted bl

Error message

WACCResult.wacc={self.wacc!r} does not match the weighted blend {expected!r} of cost_of_equity and cost_of_debt_after_tax

What it means

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).

Source

Thrown at agent/src/quantlib/valuation/dcf.py:366

    debt_weight: float
    wacc: float

    def __post_init__(self) -> None:
        """Re-check the blend arithmetic and the weight identity.

        Raises:
            ValueError: If the weights do not sum to 1, or ``wacc`` is not the
                stated weighted blend of the two costs of capital.
        """
        _validate_weights(self.equity_weight, self.debt_weight, model="WACCResult")
        expected = (
            self.equity_weight * self.cost_of_equity
            + self.debt_weight * self.cost_of_debt_after_tax
        )
        if not math.isclose(
            self.wacc, expected, rel_tol=_RECONCILIATION_TOLERANCE, abs_tol=1e-12
        ):
            raise ValueError(
                f"WACCResult.wacc={self.wacc!r} does not match the weighted "
                f"blend {expected!r} of cost_of_equity and cost_of_debt_after_tax"
            )


def wacc(
    *,
    risk_free_rate: float,
    beta: float,
    equity_risk_premium: float,
    pretax_cost_of_debt: float,
    tax_rate: float,
    capital_structure_basis: str,
    market_value_of_equity: float | None = None,
    market_value_of_debt: float | None = None,
    target_equity_weight: float | None = None,
    target_debt_weight: float | None = None,
    size_premium: float = 0.0,

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Construct WACCResult via the public wacc() function rather than manually
  2. If constructing manually, compute wacc = e_w*Ke + d_w*Kd_at and pass that exact value
  3. Recompute the blend after any field change instead of editing wacc in isolation

Example fix

# before
WACCResult(wacc=0.10, equity_weight=.5, cost_of_equity=.12, debt_weight=.5, cost_of_debt_after_tax=.04)

# after
WACCResult(wacc=.5*.12 + .5*.04, equity_weight=.5, cost_of_equity=.12, debt_weight=.5, cost_of_debt_after_tax=.04)
Defensive patterns

Strategy: validation

Validate before calling

w = equity_weight * cost_of_equity + debt_weight * cost_of_debt_after_tax
result = WACCResult(wacc=w, equity_weight=equity_weight, ...)

Try / catch

try:
    WACCResult(...)
except ValueError as e:
    raise AssertionError(f'inconsistent WACC inputs: {e}') from e

Prevention

When it happens

Trigger: 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.

Common situations: Building the result object by hand in tests or adapters instead of calling wacc(); copy-paste of numbers from a stale model run.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/1a4b8ec569155fdb. Report an issue: GitHub.