{"record":{"id":"e06c1f062f00beba","repo":"HKUDS/Vibe-Trading","slug":"comps-calendarise-metric-unknown-policy-policy-r","errorCode":null,"errorMessage":"comps.calendarise_metric: unknown policy {policy!r}, must be one of {CALENDARISATION_POLICIES}","messagePattern":"comps\\.calendarise_metric: unknown policy (.+?), must be one of (.+?)","errorType":"exception","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/comps.py","lineNumber":260,"sourceCode":"\n    Args:\n        periods: The company's raw fiscal-period figures for this metric.\n        policy: `\"ltm\"` or `\"calendar_year\"`.\n        metric_name: Name of the metric being aligned (e.g. `\"ebitda\"`), used\n            only for error messages.\n        company_name: Name of the company being aligned, used only for error\n            messages.\n\n    Returns:\n        The aligned :class:`CalendarisedMetric`.\n\n    Raises:\n        ValuationError: If `policy` is not one of `CALENDARISATION_POLICIES`,\n            or if any supplied period value is not a finite number.\n        MissingInputError: If `periods` lacks a field this policy needs.\n    \"\"\"\n    if policy not in CALENDARISATION_POLICIES:\n        raise ValuationError(\n            f\"comps.calendarise_metric: unknown policy {policy!r}, must be \"\n            f\"one of {CALENDARISATION_POLICIES}\"\n        )\n    model = f\"comps.calendarise_metric[{company_name}.{metric_name}:{policy}]\"\n\n    for name, val in (\n        (\"last_full_fiscal_year\", periods.last_full_fiscal_year),\n        (\"current_year_to_date\", periods.current_year_to_date),\n        (\"prior_year_to_date\", periods.prior_year_to_date),\n        (\"next_full_fiscal_year\", periods.next_full_fiscal_year),\n    ):\n        if val is not None and not math.isfinite(val):\n            raise ValuationError(\n                f\"{model}: {name} must be a finite number, got {val!r}\"\n            )\n\n    if policy == \"ltm\":\n        require_inputs(","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/comps.py#L242-L278","documentation":"calendarise_metric requires policy to be one of the CALENDARISATION_POLICIES constants (e.g. LTM / calendar-year style alignment rules). An unrecognized string is rejected with a ValuationError listing the allowed set, because each policy drives different required periods and weights.","triggerScenarios":"calendarise_metric(..., policy='ltm') when the constant is e.g. 'ltm_formula' or 'calendar'; passing 'LTM' with wrong casing; a config typo like 'calender_year'.","commonSituations":"Free-text policy settings in YAML/CLI; version upgrades that renamed policies; casing or spelling drift between config and library constants.","solutions":["Use the exact constant from CALENDARISATION_POLICIES (import and reference it rather than hardcoding strings).","Print/inspect CALENDARISATION_POLICIES to see valid values for your version.","Validate config values against the allowed set at startup."],"exampleFix":"# before\nfrom quantlib.valuation.comps import calendarise_metric\ncalendarise_metric(..., policy=\"LTM\")\n# after\nfrom quantlib.valuation.comps import calendarise_metric, CALENDARISATION_POLICIES\ncalendarise_metric(..., policy=CALENDARISATION_POLICIES[0])  # or exact literal, e.g. \"ltm\"","handlingStrategy":"validation","validationCode":"from quantlib.valuation.comps import CALENDARISATION_POLICIES\nif policy not in CALENDARISATION_POLICIES:\n    raise ValueError(f\"policy must be one of {CALENDARISATION_POLICIES}, got {policy!r}\")\ncalendarise_metric(..., policy=policy)","typeGuard":"from quantlib.valuation.comps import CALENDARISATION_POLICIES\ndef is_valid_policy(p) -> bool:\n    return p in CALENDARISATION_POLICIES","tryCatchPattern":null,"preventionTips":["Import and reuse CALENDARISATION_POLICIES instead of hardcoding strings.","Validate free-text policy config against the allowed set at startup."],"tags":["python","comps","calendarisation","enum-validation"],"backgroundTag":"invalid-policy-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}