microsoft/qlib · error · ValueError

The rolling window size of Kurtosis operation should >= 5

Error message

The rolling window size of Kurtosis operation should >= 5

What it means

Raised by the Kurt rolling operator (qlib/data/ops.py) when its window size N is nonzero and N < 4 — the code condition is 'N != 0 and N < 4' while the message says '>= 5'. The strict statistical minimum for kurtosis is 4 points, so N=4 passes the code check despite the message text; the message is slightly inaccurate upstream. N=0 (expanding window) is allowed.

Source

Thrown at qlib/data/ops.py:947

class Kurt(Rolling):
    """Rolling Kurtosis

    Parameters
    ----------
    feature : Expression
        feature instance
    N : int
        rolling window size

    Returns
    ----------
    Expression
        a feature instance with rolling kurtosis
    """

    def __init__(self, feature, N):
        if N != 0 and N < 4:
            raise ValueError("The rolling window size of Kurtosis operation should >= 5")
        super(Kurt, self).__init__(feature, N, "kurt")


class Max(Rolling):
    """Rolling Max

    Parameters
    ----------
    feature : Expression
        feature instance
    N : int
        rolling window size

    Returns
    ----------
    Expression
        a feature instance with rolling max
    """

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use N >= 4 (the message suggests 5; N=4 passes the check but 5+ is a safer convention for meaningful kurtosis).
  2. Use N=0 for an expanding all-history window.
  3. Exclude N in {1,2,3} from generated window candidates.

Example fix

# before
expr = "Kurt($close, 3)"

# after
expr = "Kurt($close, 5)"  # N >= 4 required by code; message recommends >= 5
Defensive patterns

Strategy: validation

Validate before calling

if N != 0 and N < 4:
    raise ValueError("Kurt window must be 0 (expanding) or >= 4 (5+ recommended)")

Type guard

def is_valid_kurt_window(n: int) -> bool:
    return n == 0 or n >= 4

Prevention

When it happens

Trigger: Building expressions like Kurt($close, 3), Kurt($close, 2), or Kurt($close, 1). Raised at expression construction time, before data loading.

Common situations: Window-size sweeps starting too low; copying the Skew minimum (3) when using Kurt, which needs at least 4; confusion caused by the error message demanding '>= 5' while the check actually allows N=4.

Related errors


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