HKUDS/Vibe-Trading · error · ValuationError
wacc: tax_rate must be within [0, 1], got {tax_rate!r}
Error message
wacc: tax_rate must be within [0, 1], got {tax_rate!r} What it means
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.
Source
Thrown at agent/src/quantlib/valuation/dcf.py:437
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(
market_value_of_equity, "market_value_of_equity", "wacc"
)
debt_mv = _require_nonnegative(
market_value_of_debt, "market_value_of_debt", "wacc"
)View on GitHub (pinned to 80ffdda44c)
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
Example fix
# before wacc(..., tax_rate=25) # after wacc(..., tax_rate=0.25)
Defensive patterns
Strategy: validation
Validate before calling
assert 0.0 <= tax_rate <= 1.0, f'tax_rate must be fraction in [0,1], got {tax_rate}'
wacc(..., tax_rate=tax_rate) Type guard
def is_fraction(x) -> TypeGuard[float]:
return isinstance(x, (int, float)) and 0.0 <= x <= 1.0 Try / catch
try:
wacc(...)
except ValuationError as e:
if 'tax_rate' in str(e):
return wacc(..., tax_rate=min(max(tax_rate / 100 if tax_rate > 1 else tax_rate, 0), 1))
raise Prevention
- 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
When it happens
Trigger: wacc(tax_rate=25) (percent instead of fraction), tax_rate=-0.1, or tax_rate=1.5 from an aggressive assumption.
Common situations: Tax rates copied from financial statements as '25%'; effective-tax-rate calculations going negative for companies with tax credits without clamping.
Related errors
- fcff_bridge: tax_rate must be within [0, 1], got {tax_rate!r
- {model}: {name} must be a number, got {value!r}
- {model}: capital-structure weights must be non-negative, got
- {model}: capital-structure weights must sum to 1 (within {_R
- WACCResult.wacc={self.wacc!r} does not match the weighted bl
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/85986b96f3723e2a.
Report an issue: GitHub.