HKUDS/Vibe-Trading · error · ValuationError

run_dcf: capital_structure_basis must be one of {CAPITAL_STR

Error message

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

What it means

run_dcf validates its capital_structure_basis enum argument against the module-level CAPITAL_STRUCTURE_BASES set before doing any work. Any value not in that set (e.g. a typo like 'target' instead of 'target_structure') raises ValuationError immediately. This is a fail-fast guard so downstream WACC and equity-bridge math never runs on an undefined basis.

Source

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

            see ``DCFResult.terminal_value``.
        gdp_growth_ceiling: Reference ceiling used only to flag (never block)
            ``terminal_growth`` -- see :data:`DEFAULT_LONG_RUN_GDP_GROWTH_CEILING`.

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

    Raises:
        MissingInputError: If any required key is absent from ``inputs``.
        ValuationError: If ``capital_structure_basis``,
            ``discounting_convention`` or ``terminal_value_method`` is
            unrecognised; if ``terminal_growth`` or ``exit_multiple`` is not
            the matching :class:`Assumption`; if ``terminal_growth.value >=``
            the built WACC; if any capital-structure, FCFF-bridge or
            balance-sheet input fails its own guard (see :func:`wacc`,
            :func:`fcff_bridge`, :func:`terminal_value`, :func:`equity_bridge`).
    """
    if capital_structure_basis not in CAPITAL_STRUCTURE_BASES:
        raise ValuationError(
            f"run_dcf: capital_structure_basis must be one of "
            f"{CAPITAL_STRUCTURE_BASES}, got {capital_structure_basis!r}"
        )
    if discounting_convention not in DISCOUNTING_CONVENTIONS:
        raise ValuationError(
            f"run_dcf: discounting_convention must be one of "
            f"{DISCOUNTING_CONVENTIONS}, got {discounting_convention!r}"
        )
    if terminal_value_method not in TERMINAL_VALUE_METHODS:
        raise ValuationError(
            f"run_dcf: terminal_value_method must be one of "
            f"{TERMINAL_VALUE_METHODS}, got {terminal_value_method!r}"
        )

    structure_fields = (
        DCF_CURRENT_STRUCTURE_FIELDS
        if capital_structure_basis == "current"
        else DCF_TARGET_STRUCTURE_FIELDS

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Check the accepted values: from the module import CAPITAL_STRUCTURE_BASES and print it; use one of those exact strings.
  2. Fix the typo/case in the config or call site (values are case-sensitive).
  3. Validate basis against CAPITAL_STRUCTURE_BASES in your config loader before invoking run_dcf.

Example fix

// before
run_dcf(base, assumptions, capital_structure_basis="target")  # ValueError
// after
from quantlib.valuation.dcf import CAPITAL_STRUCTURE_BASES  # e.g. {'current','target'}
run_dcf(base, assumptions, capital_structure_basis="target_structure")
Defensive patterns

Strategy: validation

Validate before calling

from quantlib.valuation.dcf import CAPITAL_STRUCTURE_BASES
assert capital_structure_basis in CAPITAL_STRUCTURE_BASES, f"pick from {CAPITAL_STRUCTURE_BASES}"

Type guard

def is_valid_basis(b: str) -> bool:
    from quantlib.valuation.dcf import CAPITAL_STRUCTURE_BASES
    return isinstance(b, str) and b in CAPITAL_STRUCTURE_BASES

Try / catch

try:
    result = run_dcf(...)
except ValuationError as e:
    if 'capital_structure_basis' in str(e):
        log_config_error('basis', e)

Prevention

When it happens

Trigger: Calling run_dcf(capital_structure_basis=...) with a string not in CAPITAL_STRUCTURE_BASES — misspelled basis name, wrong casing, or passing a different config key's value (e.g. a discounting_convention string).

Common situations: Config-driven DCF pipelines where the basis comes from YAML/JSON; refactors that rename basis constants; agents or LLM tool callers guessing enum values.

Related errors


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