{"record":{"id":"48a0e14642b0ba4c","repo":"microsoft/qlib","slug":"the-rolling-window-size-of-skewness-operation-shou","errorCode":null,"errorMessage":"The rolling window size of Skewness operation should >= 3","messagePattern":"The rolling window size of Skewness operation should >= 3","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/data/ops.py","lineNumber":925,"sourceCode":"class Skew(Rolling):\n    \"\"\"Rolling Skewness\n\n    Parameters\n    ----------\n    feature : Expression\n        feature instance\n    N : int\n        rolling window size\n\n    Returns\n    ----------\n    Expression\n        a feature instance with rolling skewness\n    \"\"\"\n\n    def __init__(self, feature, N):\n        if N != 0 and N < 3:\n            raise ValueError(\"The rolling window size of Skewness operation should >= 3\")\n        super(Skew, self).__init__(feature, N, \"skew\")\n\n\nclass Kurt(Rolling):\n    \"\"\"Rolling Kurtosis\n\n    Parameters\n    ----------\n    feature : Expression\n        feature instance\n    N : int\n        rolling window size\n\n    Returns\n    ----------\n    Expression\n        a feature instance with rolling kurtosis\n    \"\"\"","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/data/ops.py#L907-L943","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nexpr = \"Skew($close, 2)\"\n\n# after\nexpr = \"Skew($close, 5)\"  # any N >= 3, or N=0 for expanding window","handlingStrategy":"validation","validationCode":"if N != 0 and N < 3:\n    raise ValueError(\"Skew window must be 0 (expanding) or >= 3\")","typeGuard":"def is_valid_skew_window(n: int) -> bool:\n    return n == 0 or n >= 3","tryCatchPattern":null,"preventionTips":["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."],"tags":["qlib","expression","rolling","validation"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}