HKUDS/Vibe-Trading · error · CurrencyMismatchError

declared currency {declared!r} does not match the flows' cur

Error message

declared currency {declared!r} does not match the flows' currency {next(iter(present))!r}

What it means

If you declare a currency on a non-pre-translated series, it must equal the single currency actually present on the flows. A mismatch (e.g. declaring USD for EUR flows) raises CurrencyMismatchError rather than letting totals be attributed to the wrong currency.

Source

Thrown at agent/src/entities/cashflow.py:258

        if self.pre_translated:
            if declared is None:
                raise ValueError(
                    "pre_translated=True asserts the flows were already converted, "
                    "so the reporting currency must be named explicitly via "
                    "currency=..."
                )
        else:
            if len(present) > 1:
                raise CurrencyMismatchError(
                    "cash flows span multiple currencies "
                    f"({', '.join(sorted(present))}); convert them first and pass "
                    "pre_translated=True with the reporting currency, rather than "
                    "summing across currencies"
                )
            if declared is None:
                declared = next(iter(present)) if present else None
            elif present and declared not in present:
                raise CurrencyMismatchError(
                    f"declared currency {declared!r} does not match the flows' "
                    f"currency {next(iter(present))!r}"
                )

        object.__setattr__(self, "currency", declared)
        object.__setattr__(self, "flows", tuple(sorted(flows, key=lambda f: f.date)))

    # ─── Access ───

    def __iter__(self) -> Iterator[CashFlow]:
        """Iterate the flows in date order.

        Returns:
            An iterator over ``CashFlow`` sorted by date.
        """
        return iter(self.flows)

    def __len__(self) -> int:

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Omit currency= and let the series infer it from the flows (single-currency case)
  2. Change currency= to match the flows' actual currency
  3. If you truly want the other currency, translate the flows first (see the multi-currency error)

Example fix

# before
CashFlowSeries(flows=eur_flows, currency='USD')
# after
CashFlowSeries(flows=eur_flows)  # infers 'EUR'
Defensive patterns

Strategy: validation

Validate before calling

declared = declared or next(iter({f.currency for f in flows}), None)
series = CashFlowSeries(flows=flows, currency=declared)

Try / catch

from agent.src.entities.cashflow import CurrencyMismatchError
try:
    CashFlowSeries(flows=flows, currency='USD')
except CurrencyMismatchError:
    series = CashFlowSeries(flows=flows)  # infer from flows

Prevention

When it happens

Trigger: CashFlowSeries(flows=eur_flows, currency='USD') where every flow has currency='EUR'.

Common situations: Hard-coded reporting currency conflicting with a data source that switched denomination; case/format drift like 'usd' vs 'USD' handled by normalization but genuine currency differences not.

Related errors


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