技术指标¶
纯函数实现,不依赖 pandas / numpy,输入 list[float] 输出 list[float](或元组),
可直接在任意序列上用。也被 TdxData.get_stock_kline_with_indicators() 内部调用。
快速示例¶
closes = [b.close for b in bars]
macd_line, signal, hist = indicator.macd(closes)
rsi14 = indicator.rsi(closes, period=14)
upper, mid, lower = indicator.boll(closes, period=20, mult=2.0)
指标计算前端数据不足时,结果用 None 占位,长度与输入一致——不会截断,
方便直接和 K 线按下标对齐。
API¶
轻量技术指标(纯Python,零依赖):MACD/KDJ/RSI/BOLL/MA/EMA
函数:¶
macd
¶
MACD: DIF/DEA/MACD柱。返回与values等长。
kdj
¶
kdj(
values_high: list[float],
values_low: list[float],
values_close: list[float],
period: int = 9,
) -> dict
KDJ(简化:9日随机指标)。
compute_indicators
¶
compute_indicators(
high: list[float],
low: list[float],
close: list[float],
names: list[str],
params: dict | None = None,
tail: int | None = None,
) -> dict
计算指标,返回 {指标名: 序列}。
与 get_stock_kline_with_indicators 的关系¶
服务端侧的指标请求走 MAC 通道(get_stock_kline_with_indicators,服务端算好返回);
本地侧的指标走本模块。两者不互相依赖:
| 方式 | 位置 | 适用 |
|---|---|---|
get_stock_kline_with_indicators(...) |
服务端计算 | 想少传数据、服务端算子齐全时 |
pytdxdata.indicator.* |
本地计算 | 需要自定义参数、离线复算、和其他数据源混算 |