HKUDS/Vibe-Trading · error · ValueError

FCFFYear(year={self.year}).fcff={self.fcff!r} does not match

Error message

FCFFYear(year={self.year}).fcff={self.fcff!r} does not match the bridge total {expected_fcff!r}

What it means

FCFFYear.__post_init__ verifies fcff = nopat + D&A - capex - delta_nwc within tolerance and raises ValueError on mismatch. Ensures the stored fcff is exactly the bridge total, not an independently sourced number.

Source

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

                or ``year`` is not a positive integer.
        """
        if self.year < 1:
            raise ValueError(f"FCFFYear.year must be >= 1, got {self.year!r}")
        expected_nopat = self.ebit * (1.0 - self.tax_rate)
        if not math.isclose(
            self.nopat, expected_nopat, rel_tol=_RECONCILIATION_TOLERANCE, abs_tol=1e-9
        ):
            raise ValueError(
                f"FCFFYear(year={self.year}).nopat={self.nopat!r} does not match "
                f"ebit * (1 - tax_rate) = {expected_nopat!r}"
            )
        expected_fcff = (
            self.nopat + self.depreciation_amortization - self.capex - self.delta_nwc
        )
        if not math.isclose(
            self.fcff, expected_fcff, rel_tol=_RECONCILIATION_TOLERANCE, abs_tol=1e-9
        ):
            raise ValueError(
                f"FCFFYear(year={self.year}).fcff={self.fcff!r} does not match the "
                f"bridge total {expected_fcff!r}"
            )


def fcff_bridge(
    *,
    ebit: Sequence[float],
    tax_rate: float,
    depreciation_amortization: Sequence[float],
    capex: Sequence[float],
    delta_nwc: Sequence[float],
) -> tuple[FCFFYear, ...]:
    """Build the EBIT -> FCFF bridge for every projection year.

    Args:
        ebit: EBIT forecast, one entry per projection year, oldest first.
        tax_rate: Marginal tax rate in ``[0, 1]``, applied to every year.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Pass delta_nwc as the increase in net working capital (positive = investment) and compute fcff from the bridge
  2. Verify sign conventions of capex and delta_nwc against the formula before constructing
  3. Use fcff_bridge() to derive all fields consistently

Example fix

# before
FCFFYear(..., delta_nwc=-20.0, fcff=85.0)  # treated negative as release

# after
FCFFYear(..., delta_nwc=20.0, fcff=nopat + da - capex - 20.0)
Defensive patterns

Strategy: validation

Validate before calling

fcff = nopat + da - capex - delta_nwc
FCFFYear(..., fcff=fcff)

Try / catch

try:
    FCFFYear(...)
except ValueError as e:
    if 'bridge total' in str(e):
        raise DataImportError(f'sign convention mismatch in bridge inputs: {e}') from e
    raise

Prevention

When it happens

Trigger: Passing a fcff value from a broker template whose bridge differs (e.g. different sign convention for delta_nwc), or rounding fcff independently of the components.

Common situations: Spreadsheet FCF rows where delta_nwc is entered as a negative (cash outflow) instead of a positive investment; sign-convention mismatches when importing third-party models.

Related errors


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