HKUDS/Vibe-Trading · error · ValuationError

comps.calendarise_metric: unknown policy {policy!r}, must be

Error message

comps.calendarise_metric: unknown policy {policy!r}, must be one of {CALENDARISATION_POLICIES}

What it means

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.

Source

Thrown at agent/src/quantlib/valuation/comps.py:260

    Args:
        periods: The company's raw fiscal-period figures for this metric.
        policy: `"ltm"` or `"calendar_year"`.
        metric_name: Name of the metric being aligned (e.g. `"ebitda"`), used
            only for error messages.
        company_name: Name of the company being aligned, used only for error
            messages.

    Returns:
        The aligned :class:`CalendarisedMetric`.

    Raises:
        ValuationError: If `policy` is not one of `CALENDARISATION_POLICIES`,
            or if any supplied period value is not a finite number.
        MissingInputError: If `periods` lacks a field this policy needs.
    """
    if policy not in CALENDARISATION_POLICIES:
        raise ValuationError(
            f"comps.calendarise_metric: unknown policy {policy!r}, must be "
            f"one of {CALENDARISATION_POLICIES}"
        )
    model = f"comps.calendarise_metric[{company_name}.{metric_name}:{policy}]"

    for name, val in (
        ("last_full_fiscal_year", periods.last_full_fiscal_year),
        ("current_year_to_date", periods.current_year_to_date),
        ("prior_year_to_date", periods.prior_year_to_date),
        ("next_full_fiscal_year", periods.next_full_fiscal_year),
    ):
        if val is not None and not math.isfinite(val):
            raise ValuationError(
                f"{model}: {name} must be a finite number, got {val!r}"
            )

    if policy == "ltm":
        require_inputs(

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use the exact constant from CALENDARISATION_POLICIES (import and reference it rather than hardcoding strings).
  2. Print/inspect CALENDARISATION_POLICIES to see valid values for your version.
  3. Validate config values against the allowed set at startup.

Example fix

# before
from quantlib.valuation.comps import calendarise_metric
calendarise_metric(..., policy="LTM")
# after
from quantlib.valuation.comps import calendarise_metric, CALENDARISATION_POLICIES
calendarise_metric(..., policy=CALENDARISATION_POLICIES[0])  # or exact literal, e.g. "ltm"
Defensive patterns

Strategy: validation

Validate before calling

from quantlib.valuation.comps import CALENDARISATION_POLICIES
if policy not in CALENDARISATION_POLICIES:
    raise ValueError(f"policy must be one of {CALENDARISATION_POLICIES}, got {policy!r}")
calendarise_metric(..., policy=policy)

Type guard

from quantlib.valuation.comps import CALENDARISATION_POLICIES
def is_valid_policy(p) -> bool:
    return p in CALENDARISATION_POLICIES

Prevention

When it happens

Trigger: 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'.

Common situations: Free-text policy settings in YAML/CLI; version upgrades that renamed policies; casing or spelling drift between config and library constants.

Related errors


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