rolling_slope

czsc.rolling_slope(df: DataFrame, col: str, window=300, min_periods=100, new_col=None, **kwargs)[source]

计算序列的滚动斜率

大于0表示序列的斜率向上,小于0表示序列的斜率向下,绝对值越大表示斜率越陡峭

Parameters:
  • df – pd.DataFrame, 待计算的数据

  • col – str, 待计算的列

  • window – int, 滚动窗口大小, 默认为300

  • min_periods – int, 最小计算周期, 默认为100

  • new_col – str, 新列名,默认为 None, 表示使用 f’{col}_slope’ 作为新列名

  • kwargs

    • min_periods: int, 最小计算周期

    • method: str, 计算方法

      • linear: 使用线性回归计算斜率

      • std/mean: 使用序列的 std/mean 计算斜率

      • snr: 使用序列的 snr 计算斜率