microsoft/qlib · error · ValueError
The rolling window size of Skewness operation should >= 3
Error message
The rolling window size of Skewness operation should >= 3
What it means
Raised by the Skew rolling operator (qlib/data/ops.py) at expression construction when its window size N is nonzero and smaller than 3. Statistical skewness is undefined for fewer than 3 samples, so qlib rejects such windows immediately. N=0 in qlib convention means an expanding window over all history and is allowed.
Source
Thrown at qlib/data/ops.py:925
class Skew(Rolling):
"""Rolling Skewness
Parameters
----------
feature : Expression
feature instance
N : int
rolling window size
Returns
----------
Expression
a feature instance with rolling skewness
"""
def __init__(self, feature, N):
if N != 0 and N < 3:
raise ValueError("The rolling window size of Skewness operation should >= 3")
super(Skew, self).__init__(feature, N, "skew")
class Kurt(Rolling):
"""Rolling Kurtosis
Parameters
----------
feature : Expression
feature instance
N : int
rolling window size
Returns
----------
Expression
a feature instance with rolling kurtosis
"""View on GitHub (pinned to 79633dd950)
Solutions
- Set N >= 3, e.g. Skew($close, 5).
- If you want an expanding (all-history) window, use N=0, which is explicitly allowed.
- Filter window-size candidate lists to exclude N in {1,2} before generating expressions.
Example fix
# before expr = "Skew($close, 2)" # after expr = "Skew($close, 5)" # any N >= 3, or N=0 for expanding window
Defensive patterns
Strategy: validation
Validate before calling
if N != 0 and N < 3:
raise ValueError("Skew window must be 0 (expanding) or >= 3") Type guard
def is_valid_skew_window(n: int) -> bool:
return n == 0 or n >= 3 Prevention
- Filter hyperparameter grids: windows = [w for w in windows if w == 0 or w >= 3].
- Generate feature expressions from validated parameter lists, not free-form strings.
When it happens
Trigger: Building a feature expression like Skew($close, 2) or Skew($change, 1) — any N in {1, 2}. Evaluated when the expression string is parsed/instantiated, before any data is loaded.
Common situations: Parameter sweeps over window sizes (e.g. trying N=1..10) that include invalid small values; hand-written feature lists with short windows; porting formulas from libraries with different minimums.
Related errors
- The rolling window size of Kurtosis operation should >= 5
- {freq} is not supported in NumpyQuote
- {method} is not supported
- Invalid Qlib configuration (note: the global config has alre
- provider_uri cannot be None
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/48a0e14642b0ba4c.
Report an issue: GitHub.