Skip to content

DataStruct _indicators 模块

行情数据统计指标 Mixin 模块,提供各类技术指标和统计量计算。

模块结构

_indicators.py

QuotationIndicatorsMixin

行情数据统计指标 Mixin,通过多重继承为数据结构提供指标计算功能。

使用约束:

  • 此类仅用于多重继承,不能直接实例化
  • 必须放在继承顺序中的 QuotationDataStructBase 之后
  • 不应定义 init 方法

统计指标

基础统计

属性返回类型说明
maxpd.Series最大值
minpd.Series最小值
meanpd.Series均值
variancepd.Series方差
stdevpd.Series样本标准差
pstdevpd.Series总体标准差

价格相关

属性返回类型说明
price_diffpd.Series价格一阶差分
amplitudepd.Series振幅 (百分比)

K 线形态

属性返回类型说明
bar_pct_changepd.Series单根 K 线涨跌幅
bar_amplitudepd.Series单根 K 线振幅

高级统计

属性返回类型说明
mean_harmonicpd.Series调和平均数
modepd.Series众数
skewpd.Series偏度
kurtpd.Series峰度

使用示例

基本使用

python
from FQData.DataStruct import StockDayData

# 假设 stock 是 StockDayData 实例
print(f"最大值: {stock.max}")
print(f"最小值: {stock.min}")
print(f"均值: {stock.mean}")

价格分析

python
# 价格差分
print(f"价格差分: {stock.price_diff}")

# 振幅
print(f"振幅: {stock.amplitude}")

K 线分析

python
# 单根 K 线涨跌幅
print(f"涨跌幅: {stock.bar_pct_change}")

# 单根 K 线振幅
print(f"振幅: {stock.bar_amplitude}")

高级统计

python
# 偏度 (衡量分布偏斜程度)
print(f"偏度: {stock.skew}")

# 峰度 (衡量分布尖峭程度)
print(f"峰度: {stock.kurt}")

与基类结合使用

python
from FQData.DataStruct._base import QuotationDataStructBase
from FQData.DataStruct._indicators import QuotationIndicatorsMixin
from FQData.DataStruct._operations import QuotationOperationsMixin
from FQData.DataStruct._io import QuotationIOSMixin

class MyDataStruct(
    QuotationDataStructBase,
    QuotationIndicatorsMixin,
    QuotationOperationsMixin,
    QuotationIOSMixin
):
    def resample(self, level):
        pass

# MyDataStruct 实例同时具有基类和 Mixin 的所有方法
data = MyDataStruct(df, dtype='stock_day')
print(f"最大值: {data.max}")
print(f"均值: {data.mean}")
print(f"偏度: {data.skew}")

相关文档