ta / 指标目录
ta 支持哪些指标:43 个类、84 条输出列的对照清单
README 只列了 43 个指标的中文名,但写代码需要的是类名、 模块路径和输出方法——这三样都得自己从源码里翻。
这一页把它们一次性列全:本站在 Python 3.11.9 + ta 0.11.0 环境里逐一实例化了全部 43 个类, 记录每个类实际导出的输出序列(共 84 条)与前导 NaN 长度。表里的数字都是跑出来的,不是抄的。
完整清单
ta 的 43 个指标类分别叫什么、输出哪些列
| 类别 | 类名 | 输出列(前导 NaN 行数) | 特殊情况 |
|---|---|---|---|
| 动量 | AwesomeOscillatorIndicator | awesome_oscillator(NaN 33) | — |
| 动量 | KAMAIndicator | kama(NaN 13) | — |
| 动量 | PercentagePriceOscillator | ppo(NaN 25);ppo_hist(NaN 33);ppo_signal(NaN 33) | — |
| 动量 | PercentageVolumeOscillator | pvo(NaN 25);pvo_hist(NaN 33);pvo_signal(NaN 33) | — |
| 动量 | ROCIndicator | roc(NaN 14) | — |
| 动量 | RSIIndicator | rsi(NaN 13) | — |
| 动量 | StochRSIIndicator | stochrsi(NaN 26);stochrsi_d(NaN 30);stochrsi_k(NaN 28) | — |
| 动量 | StochasticOscillator | stoch(NaN 13);stoch_signal(NaN 15) | — |
| 动量 | TSIIndicator | tsi(NaN 37) | — |
| 动量 | UltimateOscillator | ultimate_oscillator(NaN 28) | — |
| 动量 | WilliamsRIndicator | williams_r(NaN 13) | — |
| 趋势 | ADXIndicator | adx(NaN 0);adx_neg(NaN 0);adx_pos(NaN 0) | 表头是 0 而非 NaN(adx、adx_neg、adx_pos) |
| 趋势 | AroonIndicator | aroon_down(NaN 14);aroon_indicator(NaN 14);aroon_up(NaN 14) | — |
| 趋势 | CCIIndicator | cci(NaN 13) | — |
| 趋势 | DPOIndicator | dpo(NaN 13) | — |
| 趋势 | EMAIndicator | ema_indicator(NaN 13) | — |
| 趋势 | IchimokuIndicator | ichimoku_a(NaN 25);ichimoku_b(NaN 0);ichimoku_base_line(NaN 25);ichimoku_conversion_line(NaN 8) | — |
| 趋势 | KSTIndicator | kst(NaN 14);kst_diff(NaN 14);kst_sig(NaN 14) | — |
| 趋势 | MACD | macd(NaN 25);macd_diff(NaN 33);macd_signal(NaN 33) | — |
| 趋势 | MassIndex | mass_index(NaN 47) | — |
| 趋势 | PSARIndicator | psar(NaN 0);psar_down(NaN 190);psar_down_indicator(NaN 0);psar_up(NaN 212);psar_up_indicator(NaN 0) | 表头是 0 而非 NaN(psar_down_indicator、psar_up_indicator) |
| 趋势 | SMAIndicator | sma_indicator(NaN 13) | — |
| 趋势 | STCIndicator | stc(NaN 47) | — |
| 趋势 | TRIXIndicator | trix(NaN 40) | — |
| 趋势 | VortexIndicator | vortex_indicator_diff(NaN 14);vortex_indicator_neg(NaN 14);vortex_indicator_pos(NaN 14) | — |
| 趋势 | WMAIndicator | wma(NaN 13) | — |
| 波动率 | AverageTrueRange | average_true_range(NaN 0) | 表头是 0 而非 NaN(average_true_range) |
| 波动率 | BollingerBands | bollinger_hband(NaN 13);bollinger_hband_indicator(NaN 0);bollinger_lband(NaN 13);bollinger_lband_indicator(NaN 0);bollinger_mavg(NaN 13);bollinger_pband(NaN 13);bollinger_wband(NaN 13) | 表头是 0 而非 NaN(bollinger_hband_indicator、bollinger_lband_indicator) |
| 波动率 | DonchianChannel | donchian_channel_hband(NaN 13);donchian_channel_lband(NaN 13);donchian_channel_mband(NaN 13);donchian_channel_pband(NaN 13);donchian_channel_wband(NaN 13) | — |
| 波动率 | KeltnerChannel | keltner_channel_hband(NaN 0);keltner_channel_hband_indicator(NaN 0);keltner_channel_lband(NaN 0);keltner_channel_lband_indicator(NaN 0);keltner_channel_mband(NaN 13);keltner_channel_pband(NaN 0);keltner_channel_wband(NaN 13) | 表头是 0 而非 NaN(keltner_channel_hband_indicator、keltner_channel_lband_indicator) |
| 波动率 | UlcerIndex | ulcer_index(NaN 13) | — |
| 成交量 | AccDistIndexIndicator | acc_dist_index(NaN 0) | — |
| 成交量 | ChaikinMoneyFlowIndicator | chaikin_money_flow(NaN 13) | — |
| 成交量 | EaseOfMovementIndicator | ease_of_movement(NaN 1);sma_ease_of_movement(NaN 14) | — |
| 成交量 | ForceIndexIndicator | force_index(NaN 14) | — |
| 成交量 | MFIIndicator | money_flow_index(NaN 13) | — |
| 成交量 | NegativeVolumeIndexIndicator | negative_volume_index(NaN 0) | — |
| 成交量 | OnBalanceVolumeIndicator | on_balance_volume(NaN 0) | — |
| 成交量 | VolumePriceTrendIndicator | volume_price_trend(NaN 1) | — |
| 成交量 | VolumeWeightedAveragePrice | volume_weighted_average_price(NaN 13) | — |
| 其他 | CumulativeReturnIndicator | cumulative_return(NaN 0) | 表头是 0 而非 NaN(cumulative_return) |
| 其他 | DailyLogReturnIndicator | daily_log_return(NaN 1) | — |
| 其他 | DailyReturnIndicator | daily_return(NaN 1) | — |
怎么用这张表:「输出列」一栏里的名字就是你在代码里要调用的方法名(rsi()、bollinger_mavg()…),括号里的 NaN 是该列在 400 行样本上的前导缺失行数,不是估计值。最后一列标出的类表头是 0 而不是 NaN,用 isna() 判断可用性会失效。预热长度为什么不同、fillna=True 会变成什么,见预热与 NaN 页。
命名规则
ta 的类名与输出列有什么命名规律
| 规律 | 例子 | 对写代码的影响 |
|---|---|---|
| 类名 = 指标英文名 + Indicator | RSIIndicator、AverageTrueRange、BollingerBands | 有些类没有 Indicator 后缀(ATR / BollingerBands / KeltnerChannel / MACD) |
| 输出方法 = 含义化动词短语 | rsi()、average_true_range()、bollinger_mavg() / bollinger_hband() | 一个类常有多条输出,别只取第一条 |
| MACD 存在于两个模块 | ta.trend.MACD 与 ta.momentum 里的 PercentagePriceOscillator | 导入时写清模块路径,否则容易 取到另一个同名概念的实现 |
add_all_ta_features 的列名前缀 = 模块名 | momentum_rsi、volatility_atr、trend_macd | 看到列名就知道该去哪个模块找类 |
| 同一指标可能有多个类 | PSAR 有 PSARIndicator;CCI 有 CCIIndicator | 按输出列需求选,不必两个都算 |
命名空间是本项目最容易踩的一处:import ta 之后包里没有指标类,只有 6 个 wrapper 函数。要拿类必须从子模块导入。同一个 MACD 概念同时出现在 ta.trend 与动量类指标家族里,混用时建议统一写成 from ta.trend import MACD 这种显式路径。
选型对照
想解决某个问题该看哪个指标
| 你想回答的问题 | 优先看的指标 | 为什么(口径理由) |
|---|---|---|
| 现在是不是超买/超卖 | RSI、Stochastic Oscillator、Williams %R、StochRSI | 四者都是 0–100 区间震荡器;RSI 用 Wilder 平滑,随机指标用区间位置,二者对同一段行情的判定可能相反 |
| 价格偏离均线多远 | Bollinger Bands 的 bollinger_pband / wband、Keltner Channel | 百分比带宽比价格绝对值可比性更好;BB 用标准差、KC 用 ATR,对跳空的反应不同 |
| 波动率有多大 | ATR、Ulcer Index、Donchian Channel 宽度 | ATR 是绝对幅度(与价格量级绑定),Ulcer Index 只惩罚下行回撤,用途不同 |
| 趋势方向与强度 | ADX、Aroon、Vortex、TRIX | ADX 给强度不给方向,要配合 adx_pos/adx_neg 一起看 |
| 量价是否配合 | OBV、CMF、MFI、Force Index、VWAP | OBV 只累加方向(对单日巨量不敏感),MFI 把资金流做成 0–100 指标,VWAP 需要日内或高频数据才准确 |
| 均线交叉类特征 | SMA、EMA、WMA、KAMA、MACD | KAMA 是自适应均线,参数与其它不同(wrapper 里固定 10/2/30);MACD 本质是两条 EMA 的差 |
| 收益率类特征 | Daily Return、Daily Log Return、Cumulative Return | 三者都不是技术指标而是特征变换;对数收益可加性更好,累计收益不可用于建模 |
选型原则:先确定你要回答的问题,再选指标,不要把所有指标都算出来再挑。本站在批量特征工程页实测过:一次性算全部 43 个指标会得到 86 列,其中相当一部分是同一个指标的不同表达(例如布林带一个类就贡献 7 列),直接喂给模型会带来严重共线性。
能力缺口
ta 没有哪些常见指标:缺失能力与替代方案
| 常被问到但 ta 没有的能力 | 实际情况 | 可行的替代做法 |
|---|---|---|
| K 线形态识别(锤子线、吞没等) | ta 没有形态识别函数 | 用 TA-Lib 的形态函数,或自己写规则 |
| MACD 柱状图的背离检测 | ta 只给 macd_diff 数值,不做背离判断 | 自己写峰值比较逻辑,注意别用未来数据 |
| 成交量分布 / 筹码分布 | ta 没有 | 自己按价格分桶统计;EasyClaw 侧有技能做类似分析 |
| 实时行情获取 | ta 没有任何行情接口 | 用 Tushare / akshare / yfinance 取数后交给 ta |
| 回测与绩效评估 | ta 没有回测模块 | 另配回测框架;结论前先读回测边界页 |
| 多标的批量计算 | ta 按单列 Series 计算,没有横截面排名 | 自己 groupby 循环;注意这会显著变慢 |
| 基本面指标 | ta 只处理价格与成交量 | 用财报数据库或对应技能 |
项目自己在 README 的 TODO 里列了 5 项未完成:用 NumExpr 加速、增加更多技术分析特征、加数据获取 wrapper、用 Pandas 多级索引同时算多个指标、用 Plotly/Streamlit 做可视化。也就是说「没有行情接口」和「没有多标的支持」是作者自己承认的缺口,不是使用姿势问题。
导入方式
ta 的指标类怎么导入才对
# 三种导入方式,效果不同 import ta ta.RSIIndicator # ✗ AttributeError:顶层包不导出指标类 ta.momentum.RSIIndicator # ✓ 可以:子模块在 import ta 时已被载入 from ta.momentum import RSIIndicator # ✓ 最推荐:意图最清楚 from ta.volatility import AverageTrueRange # ✓ 注意 ATR 不带 Indicator 后缀 from ta.trend import MACD # ✓ 趋势模块的 MACD
本机实测:import ta 后 dir(ta) 的公开名字只有 13 个,其中 6 个是 wrapper 函数、5 个是子模块、2 个是 utils 与 wrapper 本身。想要「一行拿到所有指标」应该用 add_all_ta_features(),而不是指望顶层包导出类。
FAQ
关于 ta 指标的常见问题
ta 一共有多少个指标?
ta.volume 9、ta.volatility 5、ta.trend 15、ta.momentum 11、ta.others 3)。这 43 个类对外一共产生 84 条输出序列,因为一个类常有多个输出(例如布林带一个类给 7 条)。README 声称的 43 与代码逐类一致,以官方 README 与本机运行结果为准。为什么 import ta 之后 ta.RSIIndicator 不存在?
ta/__init__.py 的 __all__ 只导出 6 个 wrapper 函数(add_all_ta_features 与五个分类版本的 add_*_ta),43 个指标类都在子模块里。正确写法是 from ta.momentum import RSIIndicator,或 import ta.momentum 后用全路径。这一点 README 没有明确说明。ta 里有 K 线形态识别吗?
同一个指标在 ta 里有多个类,该用哪个?
ta.trend 有 MACD 类,动量家族里另有 PercentagePriceOscillator(PPO,MACD 的归一化版本)。建议在代码里写全路径导入,避免后来接手的人混淆。能不能只装 ta 不装 numpy / pandas?
setup.py 里 install_requires 就是 ['numpy', 'pandas'],所有指标实现都建立在 Pandas 的 rolling / ewm 之上,去掉任何一个都无法运行。