{"record":{"id":"fef2e172191f7fbe","repo":"HKUDS/Vibe-Trading","slug":"coupon-frequency-cannot-be-negative-got-self-cou","errorCode":null,"errorMessage":"coupon_frequency cannot be negative, got {self.coupon_frequency!r}","messagePattern":"coupon_frequency cannot be negative, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/entities/models.py","lineNumber":377,"sourceCode":"        if self.face_value is not None:\n            face = float(self.face_value)\n            if face <= 0:\n                raise ValueError(f\"face_value must be positive, got {self.face_value!r}\")\n            object.__setattr__(self, \"face_value\", face)\n        if self.coupon_rate is not None:\n            rate = float(self.coupon_rate)\n            if rate < 0:\n                raise ValueError(f\"coupon_rate cannot be negative, got {rate!r}\")\n            if rate > 1.0:\n                raise ValueError(\n                    f\"coupon_rate must be a decimal fraction (0.05 means 5%), \"\n                    f\"got {rate!r}; a value above 1.0 is almost certainly a \"\n                    \"percentage\"\n                )\n            object.__setattr__(self, \"coupon_rate\", rate)\n        frequency = int(self.coupon_frequency)\n        if frequency < 0:\n            raise ValueError(\n                f\"coupon_frequency cannot be negative, got {self.coupon_frequency!r}\"\n            )\n        if self.coupon_rate and frequency == 0:\n            raise ValueError(\n                f\"coupon_frequency=0 marks a zero-coupon bond, but coupon_rate=\"\n                f\"{self.coupon_rate!r} is non-zero\"\n            )\n        object.__setattr__(self, \"coupon_frequency\", frequency)\n        if self.maturity_date is not None:\n            object.__setattr__(\n                self,\n                \"maturity_date\",\n                normalize_date(self.maturity_date, field_name=\"maturity_date\"),\n            )\n            if self.inception_date is not None and self.maturity_date < self.inception_date:\n                raise ValueError(\n                    f\"maturity_date {self.maturity_date} precedes inception_date \"\n                    f\"{self.inception_date}\"","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/entities/models.py#L359-L395","documentation":"Bond.__post_init__ coerces coupon_frequency with int() and rejects negative values. Frequency is coupons per year (e.g. 2 for semi-annual); 0 is a valid sentinel meaning zero-coupon, but negative counts are invalid.","triggerScenarios":"Bond(..., coupon_frequency=-1) or -2, or a negative value arising from arithmetic (e.g. subtracting a default frequency). Floats like 2.0 are int()-truncated to 2 and accepted.","commonSituations":"Misparsed spreadsheet columns with minus signs; intermediate calculations that compute frequency as a difference; sentinel values like -1 for 'unknown' leaking into the field.","solutions":["Pass a non-negative integer frequency (0 for zero-coupon, 1 annual, 2 semi-annual, 4 quarterly)","Use None or a proper optional field for unknown frequency rather than -1","Validate the frequency column at ingest against {0,1,2,12,...}"],"exampleFix":"# before\nBond(instrument_id='b1', coupon_rate=0.05, coupon_frequency=-1)\n\n# after\nBond(instrument_id='b1', coupon_rate=0.05, coupon_frequency=2)","handlingStrategy":"validation","validationCode":"freq = int(row['coupon_frequency'])\nif freq < 0:\n    raise ValueError(f'negative coupon_frequency {freq} on row {row_id}')\nBond(..., coupon_frequency=freq)","typeGuard":"def is_valid_frequency(f) -> bool:\n    return f is None or int(f) >= 0","tryCatchPattern":null,"preventionTips":["Use None for unknown frequencies instead of -1 sentinels","Whitelist common frequencies: 0, 1, 2, 4, 12"],"tags":["python","dataclass","bond","count-validation"],"backgroundTag":"numeric-range-validation","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}