HKUDS/Vibe-Trading · error · ValuationError

{model}: capital-structure weights must sum to 1 (within {_R

Error message

{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}

What it means

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.

Source

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

    """Check that a pair of capital-structure weights is usable.

    Args:
        equity_weight: Proposed ``E / (D + E)``.
        debt_weight: Proposed ``D / (D + E)``.
        model: Model name for the error message.

    Raises:
        ValuationError: If either weight is negative, or if they do not sum to
            1 within :data:`_RECONCILIATION_TOLERANCE`.
    """
    if equity_weight < 0.0 or debt_weight < 0.0:
        raise ValuationError(
            f"{model}: capital-structure weights must be non-negative, got "
            f"equity_weight={equity_weight!r} debt_weight={debt_weight!r}"
        )
    total = equity_weight + debt_weight
    if abs(total - 1.0) > _RECONCILIATION_TOLERANCE:
        raise ValuationError(
            f"{model}: capital-structure weights must sum to 1 (within "
            f"{_RECONCILIATION_TOLERANCE:g}), got equity_weight={equity_weight!r} "
            f"+ debt_weight={debt_weight!r} = {total!r}"
        )


# ---------------------------------------------------------------------------
# WACC
# ---------------------------------------------------------------------------


@dataclass(frozen=True)
class WACCResult:
    """The WACC build, with every component that fed it kept visible.

    Attributes:
        risk_free_rate: ``rf`` used in CAPM.
        beta: Levered beta used in CAPM.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Enter weights as fractions summing to exactly 1 (0.65/0.35)
  2. If using percentages, divide both by 100 (or by their sum) before the call
  3. When rounding for display, renormalize: w_i / (w_e + w_d) before passing

Example fix

# before
wacc(..., target_equity_weight=60, target_debt_weight=40)

# after
wacc(..., target_equity_weight=0.60, target_debt_weight=0.40)
Defensive patterns

Strategy: validation

Validate before calling

total = target_equity_weight + target_debt_weight
if abs(total - 1.0) > 1e-9:
    target_equity_weight /= total
    target_debt_weight /= total  # renormalize
wacc(..., target_equity_weight=target_equity_weight, target_debt_weight=target_debt_weight)

Type guard

def sums_to_one(e: float, d: float, tol: float = 1e-9) -> bool:
    return abs(e + d - 1.0) <= tol

Try / catch

try:
    wacc(...)
except ValuationError as e:
    if 'sum to 1' in str(e):
        return wacc(..., target_equity_weight=e_w/(e_w+d_w), target_debt_weight=d_w/(e_w+d_w))
    raise

Prevention

When it happens

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

Common situations: 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.

Related errors


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