{"record":{"id":"ea719127f0d2f4e6","repo":"HKUDS/Vibe-Trading","slug":"wacc-capital-structure-basis-must-be-one-of-capi","errorCode":null,"errorMessage":"wacc: capital_structure_basis must be one of {CAPITAL_STRUCTURE_BASES}, got {capital_structure_basis!r}","messagePattern":"wacc: capital_structure_basis must be one of (.+?), got (.+?)","errorType":"validation","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/dcf.py","lineNumber":432,"sourceCode":"        country_risk_premium: Additive sovereign/country premium on cost of\n            equity. Same optionality rationale as ``size_premium``.\n\n    Returns:\n        A :class:`WACCResult` with every intermediate figure visible.\n\n    Raises:\n        MissingInputError: If the market-value or target-weight pair matching\n            ``capital_structure_basis`` is not fully supplied.\n        ValuationError: If ``capital_structure_basis`` is unrecognised, if\n            ``tax_rate`` is outside ``[0, 1]``, if a market value is negative\n            or not finite, if the market value of equity plus debt is zero\n            (weights undefined), if the resulting weights are negative or do\n            not sum to 1, or if ``risk_free_rate``, ``beta``,\n            ``equity_risk_premium``, ``pretax_cost_of_debt``, ``size_premium``,\n            ``country_risk_premium`` or a target weight is not a finite number.\n    \"\"\"\n    if capital_structure_basis not in CAPITAL_STRUCTURE_BASES:\n        raise ValuationError(\n            f\"wacc: capital_structure_basis must be one of \"\n            f\"{CAPITAL_STRUCTURE_BASES}, got {capital_structure_basis!r}\"\n        )\n    if not 0.0 <= tax_rate <= 1.0:\n        raise ValuationError(f\"wacc: tax_rate must be within [0, 1], got {tax_rate!r}\")\n\n    if capital_structure_basis == \"current\":\n        missing = [\n            name\n            for name, value in (\n                (\"market_value_of_equity\", market_value_of_equity),\n                (\"market_value_of_debt\", market_value_of_debt),\n            )\n            if value is None\n        ]\n        if missing:\n            raise MissingInputError(missing, \"wacc\")\n        equity_mv = _require_nonnegative(","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/dcf.py#L414-L450","documentation":"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.","triggerScenarios":"wacc(capital_structure_basis='market') or 'Current' (case mismatch) or omitting/typo'ing the argument when passing an unexpected value.","commonSituations":"API/schema drift where the caller sends a new basis string the library version doesn't know; case-sensitive strings from user input forms.","solutions":["Use one of the literal values in CAPITAL_STRUCTURE_BASES (import it and choose/match against it)","Normalize user input to lowercase and validate membership before calling","On version upgrades, re-check CAPITAL_STRUCTURE_BASES for renamed/added bases"],"exampleFix":"# before\nwacc(..., capital_structure_basis='market')\n\n# after\nfrom quantlib.valuation.dcf import CAPITAL_STRUCTURE_BASES\nbasis = 'current' if user_basis == 'market' else user_basis\nassert basis in CAPITAL_STRUCTURE_BASES\nwacc(..., capital_structure_basis=basis)","handlingStrategy":"validation","validationCode":"from quantlib.valuation.dcf import CAPITAL_STRUCTURE_BASES\nassert capital_structure_basis in CAPITAL_STRUCTURE_BASES, f'use one of {CAPITAL_STRUCTURE_BASES}'\nwacc(..., capital_structure_basis=capital_structure_basis)","typeGuard":"def is_valid_basis(b: str) -> TypeGuard[str]:\n    return b in CAPITAL_STRUCTURE_BASES","tryCatchPattern":"try:\n    wacc(...)\nexcept ValuationError as e:\n    if 'capital_structure_basis' in str(e):\n        return wacc(..., capital_structure_basis='current')\n    raise","preventionTips":["Literal-type the basis parameter in your own code (Literal['current','target'])","Lowercase/normalize user-supplied basis strings","Re-check the allowed set after library upgrades"],"tags":["valuation","wacc","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}