microsoft/qlib · error · ValueError

This type of input {rtype} is not supported

Error message

This type of input {rtype} is not supported

What it means

In qlib/backtest/utils.py, the method that maps trading times to intraday indices (used by TradeCalendarManager for position-location bookkeeping) accepts rtype of only 'full' (whole trading range start_time~end_time) or 'step' (current step's time window). Any other rtype string raises ValueError before locate_index is called.

Source

Thrown at qlib/backtest/utils.py:163

        Returns
        -------
        Tuple[int, int]:
        """
        # potential performance issue
        assert self.level_infra is not None

        day_start = pd.Timestamp(self.start_time.date())
        day_end = epsilon_change(day_start + pd.Timedelta(days=1))
        freq = self.level_infra.get("common_infra").get("trade_exchange").freq
        _, _, day_start_idx, _ = Cal.locate_index(day_start, day_end, freq=freq)

        if rtype == "full":
            _, _, start_idx, end_index = Cal.locate_index(self.start_time, self.end_time, freq=freq)
        elif rtype == "step":
            _, _, start_idx, end_index = Cal.locate_index(*self.get_step_time(), freq=freq)
        else:
            raise ValueError(f"This type of input {rtype} is not supported")

        return start_idx - day_start_idx, end_index - day_start_idx

    def get_all_time(self) -> Tuple[pd.Timestamp, pd.Timestamp]:
        """Get the start_time and end_time for trading"""
        return self.start_time, self.end_time

    # helper functions
    def get_range_idx(self, start_time: pd.Timestamp, end_time: pd.Timestamp) -> Tuple[int, int]:
        """
        get the range index which involve start_time~end_time  (both sides are closed)

        Parameters
        ----------
        start_time : pd.Timestamp
        end_time : pd.Timestamp

        Returns

View on GitHub (pinned to 79633dd950)

Solutions

  1. Pass rtype='full' for the whole trading period or rtype='step' for the current trading step.
  2. If you need a custom window, call Cal.locate_index(start, end, freq=freq) directly with your own timestamps instead of extending rtype.

Example fix

# before
idx = cal_obj._get_start_end_index(rtype='day')
# after
idx = cal_obj._get_start_end_index(rtype='full')  # or 'step'
Defensive patterns

Strategy: validation

Validate before calling

assert rtype in ('full', 'step'), f"rtype must be 'full' or 'step', got {rtype!r}"

Type guard

def is_valid_rtype(r) -> bool:
    return r in ('full', 'step')

Prevention

When it happens

Trigger: Calling this internal helper (get_calendar_pos / index-location API of TradeCalendarManager) with rtype other than 'full' or 'step', e.g. 'day', 'range', or None.

Common situations: Custom strategies/executors subclass or call qlib's calendar utilities and invent a range type; refactor renames the literal ('total' vs 'full') and breaks the call.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/c92c25ccd51b2da5. Report an issue: GitHub.