Skip to main content

tp-quant (Trading Pattern Scanner)

tp-quant 是一个高性能的 Python 量化交易模式识别与预筛选库,内置 10+ 种几何经典形态检测、10+ 种 TA-Lib K 线形态识别,以及基于量价与指标体系的综合强度评分系统。


核心亮点

  • 几何与 K 线形态识别:自动检测头肩顶/底、三角形、楔形、双顶/底、通道等经典形态及多种 K 线组合形态。
  • 工业级 TA-Lib 集成:深度整合 TA-Lib 库,所有基础技术指标(RSI, MACD, ADX, EMA 等)均经过向量化加速与稳定性校验。
  • 智能量化评分:独有的 0-10 分综合评分体系,结合趋势维度、动能因子、成交量配合及确认信号进行动态分级。
  • 高并发与高性能:基于 Pandas 3.xNumPy 2.x 进行向量化优化,支持多线程并发扫描与大数据集处理。
  • 双模体验:同时提供简洁易用的 Python API 以及功能完善的统一命令行工具 (tp)
  • 策略回测支持:原生集成 backtrader 回测引擎,支持形态买卖信号的快速历史回测与绩效评估。

安装说明

通过 PyPI 安装

pip install tp-quant

包含回测模块安装

pip install "tp-quant[backtest]"

源码安装(本地开发)

git clone https://github.com/your-repo/tp-quant.git
cd tp-quant
pip install -e .

快速上手 (Python API)

1. 基础形态扫描

import pandas as pd
from tradingpatterns import scan_patterns, get_signals

# 加载您的 K 线数据 (包含 open, high, low, close, volume 字段)
df = pd.read_csv("ohlcv_data.csv")

# 扫描形态并获取评分与信号
results = scan_patterns(df)
print(results)

2. 高级预筛选流水线

from tradingpatterns import pre_screen_and_scan

# 执行预筛选与形态识别流水线
scan_result = pre_screen_and_scan(df, symbol="AAPL")
print("综合评分:", scan_result.get("score"))
print("通过防线:", scan_result.get("passed"))

命令行工具 (tp)

安装本项目后,可直接使用统一终端命令 tp 进行形态扫描策略回测

1. 扫描分析 (tp scan)

# 使用测试行情进行快速体验
tp -s MOCK_SYMBOL --mock

# 指定分析模式(bottom / trend / all)
tp -s MOCK_SYMBOL -m trend --mock

# 输出精简 JSON 格式(便于下游 LLM / 程序接入)
tp -s MOCK_SYMBOL --mock --json-simple 2>/dev/null

# 打印人类可读彩色表格 + Top 1 完整 JSON 结构
tp -s MOCK_SYMBOL --mock --detail

常用参数表:

参数 缩写 说明
--stock_code -s 单个代码标的
--stocks -S 多个代码(逗号分隔)
--file -f YAML / 文本文件标的列表
--mode -m 扫描模式:all / bottom / trend
--min-score - 筛选合格的综合得分下限(默认 6.0)
--mock - 使用内置测试行情进行无网调试
--workers - 并发线程数(默认自动按 CPU 核心数调度)
--json-simple - 输出精简 JSON 数组
--json - 输出完整 JSON 字段数据
--detail - 表格渲染 + 最佳标的 JSON 明细

2. 策略回测 (tp backtest)

# 基于形态信号执行买卖策略回测
tp backtest -s MOCK_SYMBOL --engine pattern --start 2024-01-01

项目结构与文档

更多详细技术设计与使用指南请参阅 docs/ 目录:


单元测试

使用 pytest 运行完整测试套件:

pytest

免责声明与许可

免责声明

本项目(tp-quant)所包含的代码、算法及模型仅供技术研究、学术交流及定量分析使用,不构成任何形式的投资建议、财务咨询或交易依据。金融市场有风险,投资需谨慎。依据本项目识别结果或回测结论所进行的任何实际交易决策,风险均由使用者自行承担。

许可协议

本项目依据 CC BY-NC-SA 4.0 协议开源。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

tp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

tp_quant-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file tp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

  • Download URL: tp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 a07363ded2a4123200e2197e2b24d5ef40b53df1fa3fe7d3a8f7939bf4c0d6d4
MD5 153e18a9522a2ac236df52bb2923f47a
BLAKE2b-256 6a04eb5d6af332d4c5316739d7f2d10ed1b74621efbb0bbef4e72cfff5b9c7b6

See more details on using hashes here.

File details

Details for the file tp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

  • Download URL: tp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 9f58a6b6224f2ed27740321873851bff49667c08a3c694e9c777e14593184db2
MD5 4aaa9c415ce811846b98d4bf6af06608
BLAKE2b-256 73270a0afe7ba29c28068590e29a463c69077f33c09d1c31ffd9fe946cf0f768

See more details on using hashes here.

File details

Details for the file tp_quant-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: tp_quant-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for tp_quant-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f56f2353c7e549f50000b85d783325ab6a6c95133ce76a8ffb2d86d7a4e3630c
MD5 4db5439533db629da40cf2a8570f58c5
BLAKE2b-256 01a16bc7959bf1f30c9595509d9fb52c052da658dcff832465e24f982b099442

See more details on using hashes here.

Release history Release notifications | RSS feed

1.4.2

3 files

1.4.1

3 files

1.4.0

3 files

1.3.0

3 files

1.2.6

3 files

1.2.5

3 files

1.2.4

3 files

1.2.3

3 files

1.2.2

3 files

1.2.1

3 files

1.2.0

3 files

1.1.4

3 files

1.1.3

3 files

1.1.2

3 files

1.1.1

3 files

1.1.0

3 files

1.0.4

3 files

1.0.3

3 files

1.0.2

3 files

1.0.1

1 file

This release

1.0.0 This release

3 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page