HKUDS/Vibe-Trading · error · CurrencyMismatchError

cash flows span multiple currencies ({', '.join(sorted(prese

Error message

cash flows span multiple currencies ({', '.join(sorted(present))}); convert them first and pass pre_translated=True with the reporting currency, rather than summing across currencies

What it means

When pre_translated is False, CashFlowSeries refuses to aggregate flows spanning more than one currency, because summing across currencies produces meaningless numbers. The error lists the offending currencies and tells you to convert first, then declare pre_translated=True with the reporting currency.

Source

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

                    f"CashFlowSeries members must be CashFlow, got "
                    f"{type(item).__name__}"
                )

        declared = (
            normalize_currency(self.currency) if self.currency is not None else None
        )
        present = {flow.currency for flow in flows}

        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 ───

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Translate the flows to one reporting currency with FxRateTable.translate_cashflows, then construct the series with pre_translated=True and currency=<reporting>
  2. If you did translate but kept per-flow currencies, overwrite each flow's currency to the reporting currency before building the series
  3. Split into one series per currency if aggregation across currencies is not intended

Example fix

# before
CashFlowSeries(flows=mixed_currency_flows)
# after
table = FxRateTable.from_rates(rates, quote_currency='USD')
translated = table.translate_cashflows(mixed_currency_flows)
series = CashFlowSeries(flows=translated, currency='USD', pre_translated=True)
Defensive patterns

Strategy: validation

Validate before calling

currencies = {f.currency for f in flows}
if len(currencies) > 1:
    flows = fx_table.translate_cashflows(flows)
series = CashFlowSeries(flows=flows, currency='USD', pre_translated=True)

Try / catch

from agent.src.entities.cashflow import CurrencyMismatchError
try:
    CashFlowSeries(flows=flows)
except CurrencyMismatchError:
    flows = fx_table.translate_cashflows(flows)
    series = CashFlowSeries(flows=flows, currency=fx_table.quote_currency, pre_translated=True)

Prevention

When it happens

Trigger: CashFlowSeries(flows=[CashFlow(..., currency='EUR'), CashFlow(..., currency='USD')]) without pre_translated.

Common situations: Multi-currency brokerage or fund statements loaded raw; appending new flows in a different currency to an existing list; forgetting an FX translation step before aggregation.

Related errors


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