Skip to main content

投机倒把 (Speculation)

基于技术面形态识别与 LLM 深度分析的量化选股框架。系统集成了高信噪比的预筛选漏斗与并发处理流水线。

核心特性 (v1.4.0)

  1. 两阶段并发流水线
    • 阶段 1:技术面初筛 (Technical Scan):基于 TradingPatternScanner v1.4.0,通过六层漏斗(流动性、价格结构、趋势背景、量能质量、生命周期、综合评分)并发扫描标的。
    • 阶段 2:AI 深度分析 (AI Analysis):对排序后的 Top 标的进行并发 LLM 分析,自动识别 底部企稳趋势跟随 策略逻辑。批量场景下会按 市场 + 日期 预生成 大盘 AI 简报,同市场当日所有标的共用同一份结论,减少 token 与判断分歧。
  2. 高信噪比过滤:不仅识别形态,更通过多维度技术标准过滤掉僵尸股、妖股及趋势背离标的。
  3. RAG 知识增强:支持 Redis 存储历史分析报告,AI 在分析时会自动参考该标的的往期研判。

快速入门

1. 环境准备

uv sync
source .venv/bin/activate

2. 技术面扫描 (不走 AI,快速寻找信号)

使用 -s basic 参数仅执行技术面初筛。

# 探测底部反转信号 (BRP)
uv run speculation -l brp -s basic -f data/china/config_etf.yaml

# 探测趋势跟随信号 (TF)
uv run speculation -l tf -s basic -f data/china/config_etf_all.yaml

# 组合扫描 (Combined)
uv run speculation -l combined -s basic -f data/china/config_a.yaml

uv run speculation -l combined -s basic -f data/china/etf/config_etf.yaml -d 2026-05-01

3. 全自动分析 (技术分析 + AI 研判)

默认模式。系统会筛选出得分最高的标的交付给 AI。

# 运行美股分析
uv run speculation -f data/usa/config_test.yaml

# 运行 A 股 ETF 深度分析
uv run speculation -l combined -f data/china/config_etf_test.yaml

选择器模式说明 (-l 参数)

模式 名称 扫描行为 (mode) 适用场景
brp 底部反转 bottom 专门识别双底、头肩底、圆弧底等“底部企稳”信号
tf 趋势跟踪 trend 专门识别上升通道、旗形、三角形等“趋势跟随”信号
combined 组合模式 all 同时探测底部反转与趋势延续信号 (默认推荐)
all 全量直通 all 扫描所有形态,且跳过技术面拦截,直接交付 AI

AI 分析 RAG(Redis Memory)

AI 分析支持 RAG:每次分析完成后将报告和总结存入 Redis,下次分析同一只股票时自动注入历史记录作为参考。

# 需启动 Redis,默认 redis://192.168.50.88:6379/0
export REDIS_URL=redis://192.168.50.88:6379/0
# 同步下大盘数据
uv run kdata-market --cn
uv run ai-analyze-stock -s sh.600000 -t 2026-03-31
uv run ai-analyze-stock -s 159825

单独工具

  • 单股 AIuv run ai-analyze-stock -s sh.600000 -t 2026-03-31(直接对指定标的做深度分析;会先取或生成当日该市场的大盘简报并注入提示词)。
  • 大盘简报uv run ai-analyze-market -m A -t 2026-03-31(仅生成大盘环境 AI 简报,与单股分析注入的是同一份缓存)。

市场 -mA(A 股主要指数)、USHKETF(与 A 股大盘同源)。默认若该日该市场的简报文件已存在则跳过 LLM;加 --force 可删缓存后重算。

简报默认落在 <REPORT_DIR>/market_briefs/{MARKET}_{YYYY-MM-DD}.md(与个股报告共用 REPORT_DIR;若设置 K_DATA_CENTER,则为 <K_DATA_CENTER>/report/market_briefs/)。也可通过环境变量 SPECULATION_MARKET_BRIEF_DIR 指定独立目录。


批量执行 (Batch Run)

针对历史回测或定期批量任务,可以使用内置的 shell 脚本按日期范围或时间间隔执行。

# 1. 按日期范围运行,每隔 5 天执行一次
./script/batch_run.sh -s 2026-01-01 -e 2026-05-01 -i 5

# 2. 运行最近 30 天的任务,每周执行一次 (间隔 7 天)
./script/batch_run.sh -n 30 -i 7 -f data/china/etf/config_etf.yaml

# 3. 运行最近 7 天,默认配置 (间隔 5 天)
./script/batch_run.sh -n 7

参数说明:

  • -s: 开始日期 (YYYY-MM-DD)
  • -e: 结束日期 (YYYY-MM-DD)
  • -n: 最近天数 (与 -s/-e 二选一)
  • -i: 间隔天数 (默认 5 天)
  • -f: 配置文件路径
  • -l: 选择器模式 (combined, brp, tf, all)

构建与部署

  • 普通构建(源码 wheel): uv run python -m build
  • 机器码分发构建(Cython): make build — 在本机(macOS 上即当前架构)生成带 macosx_… 的 wheel;wheel 内 不含 .py,资源文件由 packaging/prepare_native_build.py 自动扫描(已排除 __pycache__ / .pyc)。
    • 在 macOS 上同时出 Linux 多架构:需安装 Docker,然后:
      • make build-linux-x86_64manylinux x86_64linux/amd64
      • make build-linux-aarch64manylinux aarch64linux/arm64
      • make build-allclean 后依次打 本机 + 上述两个 Linux(产物均在 dist/)。
    • manylinux 内 Python 次版本默认与当前 $(PYTHON) 一致,可用 MANYLINUX_PY=3.12 覆盖。
    • Apple Silicon 上打 x86_64 会走模拟,速度较慢属正常。
  • 平台与标签:产物为 cp3xx-cp3xx-<platform>,与 OS + CPU + Python ABI 绑定;不能用单个 none-any wheel 替代多平台构建。
  • 安全与形态说明
    • .pyc:易被反编译,保护弱。
    • Cython / C 扩展(本 make build:分发 机器码逆向成本通常比 .pyc 高得多,但 仍可被逆向不是绝对安全;且与 OS + CPU + Python ABI 绑定,与 py3-none-any 式纯 Python wheel 不同。

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.

sp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

sp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

sp_quant-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (958.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file sp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: sp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ 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 sp_quant-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 689edcea283687272b107ebf030a3851c500186fc1c194ed71bea26f9add691d
MD5 d52793747b0ab62757f8d2d3f720d45f
BLAKE2b-256 c449199937c82f860cb99fc2f3a20fe2b2c51a5faf0a252bc1ffcfab5bbc8e83

See more details on using hashes here.

File details

Details for the file sp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: sp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.12, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ 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 sp_quant-1.0.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e97c89d8f2c25f646dddd5e65af6a463923844a009fcbf9e88ca3e39e4182e87
MD5 61d8197e200bf13dfc46674c04731334
BLAKE2b-256 b1e8100d9e90504a1e9795be6927195f8151a6a2e7d9e74e853e42d998980d95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sp_quant-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 958.6 kB
  • 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 sp_quant-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 472926fe40cb8f85a1701330997c433f9f48bd059b03e74e26cc1322cd543091
MD5 b22d6bc3c4ca588ab426a0f6e4d05929
BLAKE2b-256 5e3d8a01296f7864d6b9091181ffaf65e20cff2c7b5e2b1d798dd20943f7d6b4

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.6

3 files

1.0.5

3 files

1.0.4

3 files

1.0.3

3 files

1.0.2

3 files

1.0.1

3 files

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