HKUDS/Vibe-Trading · error · ValuationError

wacc: capital_structure_basis must be one of {CAPITAL_STRUCT

Error message

wacc: capital_structure_basis must be one of {CAPITAL_STRUCTURE_BASES}, got {capital_structure_basis!r}

What it means

The public wacc() validates capital_structure_basis against the allowed set CAPITAL_STRUCTURE_BASES (e.g. 'current' and 'target') and raises ValuationError for anything else — no silent default basis.

Source

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

        country_risk_premium: Additive sovereign/country premium on cost of
            equity. Same optionality rationale as ``size_premium``.

    Returns:
        A :class:`WACCResult` with every intermediate figure visible.

    Raises:
        MissingInputError: If the market-value or target-weight pair matching
            ``capital_structure_basis`` is not fully supplied.
        ValuationError: If ``capital_structure_basis`` is unrecognised, if
            ``tax_rate`` is outside ``[0, 1]``, if a market value is negative
            or not finite, if the market value of equity plus debt is zero
            (weights undefined), if the resulting weights are negative or do
            not sum to 1, or if ``risk_free_rate``, ``beta``,
            ``equity_risk_premium``, ``pretax_cost_of_debt``, ``size_premium``,
            ``country_risk_premium`` or a target weight is not a finite number.
    """
    if capital_structure_basis not in CAPITAL_STRUCTURE_BASES:
        raise ValuationError(
            f"wacc: capital_structure_basis must be one of "
            f"{CAPITAL_STRUCTURE_BASES}, got {capital_structure_basis!r}"
        )
    if not 0.0 <= tax_rate <= 1.0:
        raise ValuationError(f"wacc: tax_rate must be within [0, 1], got {tax_rate!r}")

    if capital_structure_basis == "current":
        missing = [
            name
            for name, value in (
                ("market_value_of_equity", market_value_of_equity),
                ("market_value_of_debt", market_value_of_debt),
            )
            if value is None
        ]
        if missing:
            raise MissingInputError(missing, "wacc")
        equity_mv = _require_nonnegative(

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use one of the literal values in CAPITAL_STRUCTURE_BASES (import it and choose/match against it)
  2. Normalize user input to lowercase and validate membership before calling
  3. On version upgrades, re-check CAPITAL_STRUCTURE_BASES for renamed/added bases

Example fix

# before
wacc(..., capital_structure_basis='market')

# after
from quantlib.valuation.dcf import CAPITAL_STRUCTURE_BASES
basis = 'current' if user_basis == 'market' else user_basis
assert basis in CAPITAL_STRUCTURE_BASES
wacc(..., capital_structure_basis=basis)
Defensive patterns

Strategy: validation

Validate before calling

from quantlib.valuation.dcf import CAPITAL_STRUCTURE_BASES
assert capital_structure_basis in CAPITAL_STRUCTURE_BASES, f'use one of {CAPITAL_STRUCTURE_BASES}'
wacc(..., capital_structure_basis=capital_structure_basis)

Type guard

def is_valid_basis(b: str) -> TypeGuard[str]:
    return b in CAPITAL_STRUCTURE_BASES

Try / catch

try:
    wacc(...)
except ValuationError as e:
    if 'capital_structure_basis' in str(e):
        return wacc(..., capital_structure_basis='current')
    raise

Prevention

When it happens

Trigger: wacc(capital_structure_basis='market') or 'Current' (case mismatch) or omitting/typo'ing the argument when passing an unexpected value.

Common situations: API/schema drift where the caller sends a new basis string the library version doesn't know; case-sensitive strings from user input forms.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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