polars_ta
Technical Indicator Operators Rewritten in polars.
We provide wrappers for some functions (like TA-Lib) that are not pl.Expr alike.
How to Install
Using pip
pip install -i https://pypi.org/simple --upgrade polars_ta
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade polars_ta # Mirror in China
Build from Source
git clone --depth=1 https://github.com/wukan1986/polars_ta.git
cd polars_ta
python -m build
cd dist
pip install polars_ta-0.1.2-py3-none-any.whl
How to Install TA-Lib
Non-official TA-Lib wheels can be downloaded from https://github.com/cgohlke/talib-build/releases
Usage
See examples folder.
# We need to modify the function name by prefixing `ts_` before using them in `expr_coodegen`
from polars_ta.prefix.tdx import *
# Import functions from `wq`
from polars_ta.prefix.wq import *
# Example
df = df.with_columns([
# Load from `wq`
*[ts_returns(CLOSE, i).alias(f'ROCP_{i:03d}') for i in (1, 3, 5, 10, 20, 60, 120)],
*[ts_mean(CLOSE, i).alias(f'SMA_{i:03d}') for i in (5, 10, 20, 60, 120)],
*[ts_std_dev(CLOSE, i).alias(f'STD_{i:03d}') for i in (5, 10, 20, 60, 120)],
*[ts_max(HIGH, i).alias(f'HHV_{i:03d}') for i in (5, 10, 20, 60, 120)],
*[ts_min(LOW, i).alias(f'LLV_{i:03d}') for i in (5, 10, 20, 60, 120)],
# Load from `tdx`
*[ts_RSI(CLOSE, i).alias(f'RSI_{i:03d}') for i in (6, 12, 24)],
])
When both min_samples and MIN_SAMPLES are set, min_samples takes precedence. default value is None.
import polars_ta
# Global settings. Priority Low
polars_ta.MIN_SAMPLES = 1
# High priority
ts_mean(CLOSE, 10, min_samples=1)
How We Designed This
- We use
Exprinstead ofSeriesto avoid usingSeriesin the calculation. Functions are no longer methods of class. - Use
wqfirst. It mimicsWorldQuant Alphaand strives to be consistent with them. - Use
taotherwise. It is apolars-style version ofTA-Lib. It tries to reuse functions fromwq. - Use
tdxlast. It also tries to import functions fromwqandta. - We keep the same signature and parameters as the original
TA-Libintalib. - If there is a naming conflict, we suggest calling
wq,ta,tdx,talibin order. The higher the priority, the closer the implementation is toExpr.
Comparison of Our Indicators and Others
See compare
Handling Null/NaN Values
See nan_to_null
Debugging
git clone --depth=1 https://github.com/wukan1986/polars_ta.git
cd polars_ta
pip install -e .
Notice:
If you have added some functions in ta or tdx, please run prefix_ta.py or prefix_tdx.py inside the tools folder to generate the corrected Python script (with the prefix added).
This is required to use in expr_codegen.
Reference
- https://github.com/pola-rs/polars
- https://github.com/TA-Lib/ta-lib
- https://github.com/twopirllc/pandas-ta
- https://github.com/bukosabino/ta
- https://github.com/peerchemist/finta
- https://github.com/wukan1986/ta_cn
- https://support.worldquantbrain.com/hc/en-us/community/posts/20278408956439-从价量看技术指标总结-Technical-Indicator-
- https://platform.worldquantbrain.com/learn/operators/operators
polars_ta
基于polars的算子库。实现量化投研中常用的技术指标、数据处理等函数。对于不易翻译成Expr的库(如:TA-Lib)也提供了函数式调用的封装
安装
在线安装
pip install -i https://pypi.org/simple --upgrade polars_ta # 官方源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade polars_ta # 国内镜像源
源码安装
git clone --depth=1 https://github.com/wukan1986/polars_ta.git
cd polars_ta
python -m build
cd dist
pip install polars_ta-0.1.2-py3-none-any.whl
TA-Lib安装
Windows用户不会安装可从https://github.com/cgohlke/talib-build/releases 下载对应版本whl文件
使用方法
参考examples目录即可,例如:
# 如果需要在`expr_codegen`中使用,需要有`ts_`等前权,这里导入提供了前缀
from polars_ta.prefix.tdx import *
# 导入wq公式
from polars_ta.prefix.wq import *
# 演示生成大量指标
df = df.with_columns([
# 从wq中导入指标
*[ts_returns(CLOSE, i).alias(f'ROCP_{i:03d}') for i in (1, 3, 5, 10, 20, 60, 120)],
*[ts_mean(CLOSE, i).alias(f'SMA_{i:03d}') for i in (5, 10, 20, 60, 120)],
*[ts_std_dev(CLOSE, i).alias(f'STD_{i:03d}') for i in (5, 10, 20, 60, 120)],
*[ts_max(HIGH, i).alias(f'HHV_{i:03d}') for i in (5, 10, 20, 60, 120)],
*[ts_min(LOW, i).alias(f'LLV_{i:03d}') for i in (5, 10, 20, 60, 120)],
# 从tdx中导入指标
*[ts_RSI(CLOSE, i).alias(f'RSI_{i:03d}') for i in (6, 12, 24)],
])
当min_samples和MIN_SAMPLES都设置时,以min_samples为准,默认值为None
import polars_ta
# 全局设置。优先级低
polars_ta.MIN_SAMPLES = 1
# 指定函数。优先级高
ts_mean(CLOSE, 10, min_samples=1)
设计原则
- 调用方法由
成员函数换成独立函数。输入输出使用Expr,避免使用Series - 优先实现
wq公式,它仿WorldQuant Alpha公式,与官网尽量保持一致。如果部分功能实现在此更合适将放在此处 - 其次实现
ta公式,它相当于TA-Lib的polars风格的版本。优先从wq中导入更名 - 最后实现
tdx公式,它也是优先从wq和ta中导入 talib的函数名与参数与原版TA-Lib完全一致- 如果出现了命名冲突,建议调用优先级为
wq、ta、tdx、talib。因为优先级越高,实现方案越接近于Expr
指标区别
请参考compare
空值处理
请参考nan_to_null
开发调试
git clone --depth=1 https://github.com/wukan1986/polars_ta.git
cd polars_ta
pip install -e .
注意:如果你在ta或tdx中添加了新的函数,请再运行tools下的prefix_ta.py或prefix_tdx.py,用于生成对应的前缀文件。前缀文件方便在expr_codegen中使用
文档生成
pip install -r requirements-docs.txt
mkdocs build
文档生成在site目录下,其中的llms-full.txt可以作为大语言模型的知识库导入。
也可以通过以下链接导入: https://polars-ta.readthedocs.io/en/latest/llms-full.txt
提示词
由于llms-full.txt信息不适合做提示词,所以tools/prompt.py提供了生成更简洁算子清单的功能。
用户也可以直接使用prompt.txt(欢迎提示词工程专家帮忙改进,做的更准确)
参考
- https://github.com/pola-rs/polars
- https://github.com/TA-Lib/ta-lib
- https://github.com/twopirllc/pandas-ta
- https://github.com/bukosabino/ta
- https://github.com/peerchemist/finta
- https://github.com/wukan1986/ta_cn
- https://support.worldquantbrain.com/hc/en-us/community/posts/20278408956439-从价量看技术指标总结-Technical-Indicator-
Metadata
Release files for polars-ta 0.5.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| polars_ta-0.5.18.tar.gz | 70.6 kB | With provenance | Details for polars_ta-0.5.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polars_ta-0.5.18-py3-none-any.whl | Python 3 | none | any | Details for polars_ta-0.5.18-py3-none-any.whl |
Total release size: 162.0 kB
Release files / polars_ta-0.5.18.tar.gz
| Download URL | polars_ta-0.5.18.tar.gz |
|---|---|
| Size | 70.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3724fa75f7bf03f7767ae189ea15059f49e47d12e031cac63246277dcae0b737
|
|
BLAKE2b-256 checksum How to use checksums |
da3896bc03ec0eb5abf8f5f5f31b0d90d46431d6c01d3156621fe64c2193db6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / polars_ta-0.5.18-py3-none-any.whl
| Download URL | polars_ta-0.5.18-py3-none-any.whl |
|---|---|
| Size | 91.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5892f4331480b977742780d1909199cf215032e58b87539fbf42eb2c7cafcd9
|
|
BLAKE2b-256 checksum How to use checksums |
34fda4774230995579a8d6db99903e927d988ca7726b56436cb177045a1c604b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for polars-ta 0.5.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for polars_ta-0.5.18.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.