和顺 / 衡律 返回所属 Agent
9.2

均线与动量指标的计算及初值

原能力

实现规定的均线和动量计算,统一初值、窗口、缺数与不足样本的处理。(合同附件 R7 9.2)

首选项目

Qlib(MIT)。 Qlib

匹配范围

ops Mean、Ref、EMA 实现部分滚动均线/动量。

源码

Qlib · class Mean(

qlib/data/ops.py · 827–840 行。 在 GitHub 查看源码 · 许可证与声明

源码片段
class Mean(Rolling):
    """Rolling Mean (MA)

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

    Returns
    ----------
    Expression
        a feature instance with rolling average
  • # Copyright (c) Microsoft Corporation.

Qlib · class Ref(

qlib/data/ops.py · 781–794 行。 在 GitHub 查看源码 · 许可证与声明

源码片段
class Ref(Rolling):
    """Feature Reference

    Parameters
    ----------
    feature : Expression
        feature instance
    N : int
        N = 0, retrieve the first data; N > 0, retrieve data of N periods ago; N < 0, future data

    Returns
    ----------
    Expression
        a feature instance with target reference
  • # Copyright (c) Microsoft Corporation.

Qlib · class EMA(

qlib/data/ops.py · 1349–1362 行。 在 GitHub 查看源码 · 许可证与声明

源码片段
class EMA(Rolling):
    """Rolling Exponential Mean (EMA)

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

    Returns
    ----------
    Expression
        a feature instance with regression r-value square of given window
  • # Copyright (c) Microsoft Corporation.

实现与验收要点

原窗口、初值、缺数、延迟和不足样本语义。