{"record":{"id":"85986b96f3723e2a","repo":"HKUDS/Vibe-Trading","slug":"wacc-tax-rate-must-be-within-0-1-got-tax-rat","errorCode":null,"errorMessage":"wacc: tax_rate must be within [0, 1], got {tax_rate!r}","messagePattern":"wacc: tax_rate must be within \\[0, 1\\], got (.+?)","errorType":"validation","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/dcf.py","lineNumber":437,"sourceCode":"\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(\n            market_value_of_equity, \"market_value_of_equity\", \"wacc\"\n        )\n        debt_mv = _require_nonnegative(\n            market_value_of_debt, \"market_value_of_debt\", \"wacc\"\n        )","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/dcf.py#L419-L455","documentation":"wacc() requires tax_rate to be a fraction in [0, 1] (not percent, not negative). Values outside that interval are rejected with ValuationError before any computation.","triggerScenarios":"wacc(tax_rate=25) (percent instead of fraction), tax_rate=-0.1, or tax_rate=1.5 from an aggressive assumption.","commonSituations":"Tax rates copied from financial statements as '25%'; effective-tax-rate calculations going negative for companies with tax credits without clamping.","solutions":["Pass tax_rate as a decimal fraction: 25% -> 0.25","Clamp or validate computed effective tax rates to [0,1] before the call","Catch ValuationError to report the offending tax_rate value from the message"],"exampleFix":"# before\nwacc(..., tax_rate=25)\n\n# after\nwacc(..., tax_rate=0.25)","handlingStrategy":"validation","validationCode":"assert 0.0 <= tax_rate <= 1.0, f'tax_rate must be fraction in [0,1], got {tax_rate}'\nwacc(..., tax_rate=tax_rate)","typeGuard":"def is_fraction(x) -> TypeGuard[float]:\n    return isinstance(x, (int, float)) and 0.0 <= x <= 1.0","tryCatchPattern":"try:\n    wacc(...)\nexcept ValuationError as e:\n    if 'tax_rate' in str(e):\n        return wacc(..., tax_rate=min(max(tax_rate / 100 if tax_rate > 1 else tax_rate, 0), 1))\n    raise","preventionTips":["Represent all rates as decimals everywhere in the pipeline","Add a single to_fraction() helper for percent-sourced values","Watch for negative effective tax rates from tax credits"],"tags":["valuation","wacc","percent-vs-fraction","range-validation"],"backgroundTag":"percent-instead-of-fraction","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}