{"record":{"id":"33bab4fbcb574641","repo":"HKUDS/Vibe-Trading","slug":"rate-must-be-finite-and-strictly-positive-it-is","errorCode":null,"errorMessage":"rate must be finite and strictly positive -- it is quote-per-base units -- got {rate!r}; a zero or negative rate would silently zero out or flip the sign of every flow translated with it","messagePattern":"rate must be finite and strictly positive -- it is quote-per-base units -- got (.+?); a zero or negative rate would silently zero out or flip the sign of every flow translated with it","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/cashflow.py","lineNumber":494,"sourceCode":"                unsupported, or the rate is not finite and strictly positive.\n        \"\"\"\n        object.__setattr__(\n            self,\n            \"base_currency\",\n            normalize_currency(self.base_currency, field_name=\"base_currency\"),\n        )\n        object.__setattr__(\n            self,\n            \"quote_currency\",\n            normalize_currency(self.quote_currency, field_name=\"quote_currency\"),\n        )\n        object.__setattr__(self, \"date\", normalize_date(self.date))\n        try:\n            rate = float(self.rate)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"rate must be numeric, got {self.rate!r}\") from exc\n        if not math.isfinite(rate) or rate <= 0:\n            raise ValueError(\n                f\"rate must be finite and strictly positive -- it is \"\n                f\"quote-per-base units -- got {rate!r}; a zero or negative \"\n                \"rate would silently zero out or flip the sign of every flow \"\n                \"translated with it\"\n            )\n        object.__setattr__(self, \"rate\", rate)\n\n\n@dataclass(frozen=True)\nclass FxRateTable:\n    \"\"\"A lookup of FX rates, every entry quoted against one fixed currency.\n\n    All entries must share the same ``quote_currency``: a table that mixed\n    quote currencies would make \"translate to X\" ambiguous, so that is\n    rejected at construction rather than left to whichever rate happens to be\n    looked up first.\n\n    Attributes:","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/cashflow.py#L476-L512","documentation":"An FxRate must be finite and strictly positive because the rate is quote-per-base units: zero would null every translated flow and a negative rate would flip every sign. NaN/inf/0/negative values are rejected at construction.","triggerScenarios":"FxRate(..., rate=0), rate=-1.085, rate=float('nan'), or rate=float('inf'). Also inverted quotes producing nonsense like tiny values are numerically fine but 1/0-derived values are not.","commonSituations":"Computing rates by division (base/quote instead of quote/base) that yields zero or negative numbers; parsing 'inf' or 'NaN' strings from a feed; unit-test fixtures with rate=0 placeholders.","solutions":["Fix the rate value to the correct positive quote-per-base number (e.g. USD per EUR = 1.0850, not EUR per USD)","If the rate came from a division, correct the direction: rate = quote_amount / base_amount","Reject or skip bad rates at ingest with a finiteness/positivity check"],"exampleFix":"# before\nFxRate('EUR','USD',d, rate=1/1.0850 if wrong else 0)\n# after\nFxRate('EUR','USD',d, rate=1.0850)","handlingStrategy":"validation","validationCode":"if not (math.isfinite(rate) and rate > 0):\n    raise BadRateError(f'{rate!r}')","typeGuard":"def is_valid_rate(v) -> bool:\n    return isinstance(v, (int, float)) and math.isfinite(v) and v > 0","tryCatchPattern":"try:\n    FxRate(...)\nexcept ValueError as e:\n    if 'strictly positive' in str(e):\n        rate = 1.0 / rate if rate else None  # possibly inverted source","preventionTips":["Compute rates as quote/base, verify with a known pair (EUR/USD ~ 1.08)","Sanity-check rate ranges (0 < rate < 1000) at ingest"],"tags":["python","fx-rate","validation"],"backgroundTag":"invalid-fx-rate-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}