stock-analysis-plugin 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +498 -0
  2. package/package.json +88 -0
  3. package/pi/index.ts +1142 -0
  4. package/schemas/market_review_schema.json +176 -0
  5. package/schemas/report_schema.json +131 -0
  6. package/scripts/setup-python.mjs +57 -0
  7. package/scripts/sync-version.sh +56 -0
  8. package/scripts/venv-python.mjs +20 -0
  9. package/skills/bottom-volume/SKILL.md +63 -0
  10. package/skills/bottom-volume/scripts/gather.py +22 -0
  11. package/skills/box-oscillation/SKILL.md +72 -0
  12. package/skills/box-oscillation/scripts/gather.py +22 -0
  13. package/skills/bull-trend/SKILL.md +60 -0
  14. package/skills/bull-trend/scripts/gather.py +22 -0
  15. package/skills/chan-theory/SKILL.md +71 -0
  16. package/skills/chan-theory/scripts/gather.py +22 -0
  17. package/skills/dragon-head/SKILL.md +69 -0
  18. package/skills/dragon-head/scripts/gather.py +22 -0
  19. package/skills/emotion-cycle/SKILL.md +65 -0
  20. package/skills/emotion-cycle/scripts/gather.py +22 -0
  21. package/skills/event-driven/SKILL.md +73 -0
  22. package/skills/event-driven/scripts/gather.py +22 -0
  23. package/skills/expectation-repricing/SKILL.md +72 -0
  24. package/skills/expectation-repricing/scripts/gather.py +22 -0
  25. package/skills/growth-quality/SKILL.md +74 -0
  26. package/skills/growth-quality/scripts/gather.py +22 -0
  27. package/skills/hot-theme/SKILL.md +74 -0
  28. package/skills/hot-theme/scripts/gather.py +22 -0
  29. package/skills/ma-crossover/SKILL.md +63 -0
  30. package/skills/ma-crossover/scripts/gather.py +22 -0
  31. package/skills/market-review/SKILL.md +70 -0
  32. package/skills/market-review/scripts/gather.py +23 -0
  33. package/skills/one-yang-three-yin/SKILL.md +74 -0
  34. package/skills/one-yang-three-yin/scripts/gather.py +22 -0
  35. package/skills/shrink-pullback/SKILL.md +59 -0
  36. package/skills/shrink-pullback/scripts/gather.py +22 -0
  37. package/skills/stock-analysis/SKILL.md +134 -0
  38. package/skills/stock-analysis/scripts/gather.py +22 -0
  39. package/skills/stock-screener/SKILL.md +68 -0
  40. package/skills/stock-screener/scripts/gather.py +22 -0
  41. package/skills/strategy-backtest/SKILL.md +129 -0
  42. package/skills/strategy-backtest/scripts/gather.py +23 -0
  43. package/skills/volume-breakout/SKILL.md +58 -0
  44. package/skills/volume-breakout/scripts/gather.py +22 -0
  45. package/skills/wave-theory/SKILL.md +67 -0
  46. package/skills/wave-theory/scripts/gather.py +22 -0
  47. package/skills/wisburg-research/SKILL.md +119 -0
  48. package/strategies/examples/bottom_volume.yaml +47 -0
  49. package/strategies/examples/box_oscillation.yaml +41 -0
  50. package/strategies/examples/bull_trend.yaml +42 -0
  51. package/strategies/examples/dragon_head.yaml +45 -0
  52. package/strategies/examples/emotion_cycle.yaml +43 -0
  53. package/strategies/examples/ma_crossover.yaml +34 -0
  54. package/strategies/examples/rsi_oversold.yaml +35 -0
  55. package/strategies/examples/shrink_pullback.yaml +45 -0
  56. package/strategies/examples/volume_breakout.yaml +42 -0
  57. package/templates/_macros.j2 +90 -0
  58. package/templates/market_review/full.md.j2 +103 -0
  59. package/templates/stock_analysis/brief.md.j2 +28 -0
  60. package/templates/stock_analysis/full.md.j2 +108 -0
  61. package/tools/__init__.py +0 -0
  62. package/tools/alert_rules.py +243 -0
  63. package/tools/anomaly_detect.py +575 -0
  64. package/tools/backtest.py +764 -0
  65. package/tools/capabilities.py +108 -0
  66. package/tools/diagnostics.py +146 -0
  67. package/tools/gather.py +157 -0
  68. package/tools/import_parser.py +279 -0
  69. package/tools/market_regime.py +252 -0
  70. package/tools/market_review.py +155 -0
  71. package/tools/name_resolver.py +136 -0
  72. package/tools/pattern.py +515 -0
  73. package/tools/position_context.py +161 -0
  74. package/tools/report_renderer.py +116 -0
  75. package/tools/requirements.txt +15 -0
  76. package/tools/risk_screening.py +323 -0
  77. package/tools/screener.py +219 -0
  78. package/tools/search_intel.py +504 -0
  79. package/tools/stock_data.py +1721 -0
  80. package/tools/technical.py +642 -0
  81. package/tools/trading_calendar.py +226 -0
  82. package/tools/volume_analysis.py +178 -0
  83. package/tools/watchlist.py +66 -0
  84. package/tools/watchlist_context.py +185 -0
package/README.md ADDED
@@ -0,0 +1,498 @@
1
+ # stock-analysis-plugin
2
+
3
+ [![npm](https://img.shields.io/npm/v/@weaxs/stock-analysis-plugin?label=npm&logo=npm)](https://www.npmjs.com/package/@weaxs/stock-analysis-plugin)
4
+ [![PyPI](https://img.shields.io/pypi/v/stock-analysis-plugin?label=pypi&logo=pypi&logoColor=white)](https://pypi.org/project/stock-analysis-plugin/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+ [![Python](https://img.shields.io/badge/python-%3E=3.10-blue?logo=python&logoColor=white)](https://www.python.org/)
7
+
8
+ A 股 / 港股 / 美股 / 日股 / 韩股 / 台股综合分析、多因子选股和策略回测工具集,可作为 [Pi Agent](https://github.com/anthropics/pi-agent) Extension、[Hermes Agent](https://github.com/NousResearch/hermes-agent) Plugin、[OpenClaw](https://docs.openclaw.ai/) Plugin,或 [DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness) Plugin 使用。
9
+
10
+ 底层共享同一套 Python CLI 工具和 SKILL.md 工作流,上层分别适配四个平台的注册机制。
11
+
12
+ ## 目录
13
+
14
+ - [功能概览](#功能概览)
15
+ - [安装](#安装)
16
+ - [Pi Agent Extension](#pi-agent-extension)
17
+ - [Hermes Agent Plugin](#hermes-agent-plugin)
18
+ - [OpenClaw Plugin](#openclaw-plugin)
19
+ - [dsh (DeepSeek Harness) Plugin](#dsh-deepseek-harness-plugin)
20
+ - [Python 依赖](#python-依赖)
21
+ - [快速开始](#快速开始)
22
+ - [Skills 一览](#skills-一览)
23
+ - [工具列表](#工具列表)
24
+ - [策略回测 DSL](#策略回测-dsl)
25
+ - [市场路由规则](#市场路由规则)
26
+ - [独立 CLI 使用](#独立-cli-使用)
27
+ - [项目结构](#项目结构)
28
+ - [致谢](#致谢)
29
+ - [常见问题](#常见问题)
30
+ - [License](#license)
31
+
32
+ ## 功能概览
33
+
34
+ - **39 个工具** — 行情数据、技术分析、K 线形态、资金流向、财务指标、新闻舆情、风险筛查、市场状态等
35
+ - **20 个 Skills** — 综合分析、全市场选股、策略回测 + 17 个策略方法论(缠论、波浪、龙头、情绪周期等)
36
+ - **策略回测引擎** — YAML DSL 定义策略,参数化条件组合,自动诊断 + LLM 变异优化
37
+ - **多数据源 Failover** — 9 个数据源自动容灾切换(akshare / tushare / efinance / pytdx / baostock / yfinance / finnhub / longbridge / alphavantage)
38
+ - **社交舆情增强** — A 股(东财股吧 + 雪球)/ 美港股(Reddit / X / Polymarket),市场自动路由
39
+ - **四平台适配** — 同一套工具同时支持 Pi Agent、Hermes Agent、OpenClaw 和 dsh
40
+
41
+ ## 安装
42
+
43
+ > 所有 npm 包同时以 scoped(`@weaxs/*`)和非 scoped 同名两种名字发布,内容一致,任选其一即可。
44
+
45
+ ### Pi Agent Extension
46
+
47
+ ```bash
48
+ # 全局安装
49
+ cd ~/.pi/agent/extensions
50
+ npm install @weaxs/stock-analysis-plugin
51
+
52
+ # 或项目级安装
53
+ mkdir -p .pi/extensions && cd .pi/extensions
54
+ npm install @weaxs/stock-analysis-plugin
55
+ ```
56
+
57
+ > 也可以直接 `git clone git@github.com:Weaxs/stock-analysis-plugin.git` 使用源码版本。
58
+
59
+ Pi 启动后自动加载,输入 `/skills` 确认。详见 [Pi Agent 接入指南](docs/pi-integration.md)([English](docs/pi-integration.en.md))。
60
+
61
+ ### Hermes Agent Plugin
62
+
63
+ ```bash
64
+ pip install stock-analysis-plugin
65
+ ```
66
+
67
+ 安装后 Hermes 通过 `hermes_agent.plugins` entry point 自动发现并注册,无需手动复制目录。
68
+
69
+ 或在 Python 中直接注册:
70
+
71
+ ```python
72
+ from hermes import register
73
+ register(ctx)
74
+ ```
75
+
76
+ 详见 [Hermes Agent 接入指南](docs/hermes-integration.md)([English](docs/hermes-integration.en.md))。
77
+
78
+ ### OpenClaw Plugin
79
+
80
+ ```bash
81
+ openclaw plugins install clawhub:@weaxs/openclaw-stock-analysis
82
+ ```
83
+
84
+ OpenClaw Gateway 启动后自动加载并注册 39 个 tool。安装时 postinstall 会自动建 `.venv` 并装好 Python 依赖(前提:本机有 `python3 >= 3.9`)。
85
+
86
+ 详见 [OpenClaw 接入指南](docs/openclaw-integration.md),或 plugin 自身说明 [`openclaw/README.md`](openclaw/README.md)。
87
+
88
+ ### dsh (DeepSeek Harness) Plugin
89
+
90
+ ```bash
91
+ dsh plugin --profile <你的profile> add @weaxs/dsh-stock-analysis
92
+ dsh --profile <你的profile>
93
+ ```
94
+
95
+ 作为 dsh bundle 安装:`dsh plugin add` 会把 `cordis.patch.yml` 叠加进 profile 组合,注册 39 个 tool + 20 个 skill。postinstall 自动建 `.venv`(pnpm 需在 profile 的 `pnpm-workspace.yaml` 里给本包配 `allowBuilds`,否则回退系统 `python3`)。
96
+
97
+ 详见 [`dsh/README.md`](dsh/README.md)。
98
+
99
+ ### Python 依赖
100
+
101
+ ```bash
102
+ pip install -r tools/requirements.txt
103
+ ```
104
+
105
+ 主要依赖:
106
+
107
+ | 包 | 用途 |
108
+ |---|------|
109
+ | akshare | A 股数据源(行情、资金流、财务、新闻,含 A 股 ETF) |
110
+ | yfinance | 港股 / 美股 / 日股 / 韩股 / 台股数据源 |
111
+ | pandas / numpy | 数据处理和数值计算 |
112
+ | exchange-calendars | 交易日历(A/HK/US/JP/KR/TW) |
113
+ | newspaper4k | 新闻正文提取 |
114
+ | pypinyin | 股票名称拼音搜索 |
115
+ | pytdx | A 股 TDX 行情(免费兜底源) |
116
+ | longport | 港股 / 美股 Longbridge SDK |
117
+
118
+ ### 环境变量
119
+
120
+ **数据源(可选,配置后自动加入 Failover 链):**
121
+
122
+ | 环境变量 | 用途 |
123
+ |---------|------|
124
+ | `TUSHARE_TOKEN` | Tushare 数据源(A 股 K 线 / 行情) |
125
+ | `LONGBRIDGE_APP_KEY` | Longbridge SDK(港股 / 美股) |
126
+ | `LONGBRIDGE_APP_SECRET` | Longbridge SDK |
127
+ | `LONGBRIDGE_ACCESS_TOKEN` | Longbridge SDK |
128
+ | `ALPHAVANTAGE_API_KEY` | Alpha Vantage(美股 K 线 / 行情) |
129
+ | `FINNHUB_API_KEY` | Finnhub(港股 / 美股) |
130
+
131
+ **搜索引擎(可选,配置任一即可):**
132
+
133
+ | 环境变量 | 用途 |
134
+ |---------|------|
135
+ | `TAVILY_API_KEY` | Tavily 搜索 |
136
+ | `BRAVE_API_KEY` | Brave 搜索 |
137
+ | `SERPAPI_KEY` | SerpAPI |
138
+ | `BOCHA_API_KEY` | Bocha AI 搜索 |
139
+ | `SEARXNG_BASE_URLS` | SearXNG 自建实例地址(逗号分隔多个,无需 Key,兜底用) |
140
+
141
+ **社交舆情(可选):**
142
+
143
+ | 环境变量 | 用途 |
144
+ |---------|------|
145
+ | `SENTIMENT_API_URL` | 舆情 API 地址(默认 `https://api.adanos.org`) |
146
+ | `SENTIMENT_API_KEY` | 舆情 API 密钥 |
147
+
148
+ ## 快速开始
149
+
150
+ ### 综合分析
151
+
152
+ ```
153
+ /skill:stock-analysis
154
+
155
+ 帮我分析贵州茅台(600519)
156
+ ```
157
+
158
+ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息面,输出多维度研报。
159
+
160
+ ### 全市场选股
161
+
162
+ ```
163
+ /skill:stock-screener
164
+
165
+ 帮我从 A 股中筛选出低估值+高成长的股票,要求 PE < 30、PB < 5、市值 > 100 亿
166
+ ```
167
+
168
+ ### 策略回测
169
+
170
+ ```
171
+ /skill:strategy-backtest
172
+
173
+ 用 RSI 超卖反弹策略回测茅台,时间段 2024 年全年
174
+ ```
175
+
176
+ ### 特定策略视角
177
+
178
+ ```
179
+ /skill:chan-theory
180
+ 用缠论分析一下 600519 当前的走势结构
181
+
182
+ /skill:wave-theory
183
+ 用波浪理论分析 AAPL 的浪形位置
184
+ ```
185
+
186
+ ## Skills 一览
187
+
188
+ ### 核心 Workflow(3 个)
189
+
190
+ | Skill | 调用方式 | 功能 |
191
+ |-------|----------|------|
192
+ | 综合分析 | `/skill:stock-analysis` | 技术面 + 基本面 + 资金面 + 消息面多维研判,输出结构化研报 |
193
+ | 全市场选股 | `/skill:stock-screener` | L1 多因子硬筛 → L2 LLM 智能排序 → 输出推荐列表 |
194
+ | 策略回测 | `/skill:strategy-backtest` | YAML 策略定义 → 回测 → 诊断 → LLM 变异优化 → 迭代 |
195
+
196
+ ### 策略方法论(12 个)
197
+
198
+ | Skill | 调用方式 | 方法论 |
199
+ |-------|----------|--------|
200
+ | 趋势追踪 | `/skill:bull-trend` | 均线排列 + MACD 方向 + 趋势阶段判断 |
201
+ | 缩量回调 | `/skill:shrink-pullback` | 上升趋势中的缩量洗盘识别 |
202
+ | 均线金叉 | `/skill:ma-crossover` | MA5/10/20/60 交叉信号 + 金叉质量评估 |
203
+ | 放量突破 | `/skill:volume-breakout` | 关键阻力位的放量突破确认 |
204
+ | 底部放量 | `/skill:bottom-volume` | 底部区域异动放量 → 主力建仓信号 |
205
+ | 龙头战法 | `/skill:dragon-head` | 板块龙头识别 + 龙头 vs 跟风判断 |
206
+ | 缠论 | `/skill:chan-theory` | 笔 → 段 → 中枢 → 背驰 → 买卖点 |
207
+ | 波浪理论 | `/skill:wave-theory` | Elliott 5 浪推动 + 3 浪调整 + 斐波那契 |
208
+ | 箱体震荡 | `/skill:box-oscillation` | 箱体区间识别 + 支撑压力间波段操作 |
209
+ | 情绪周期 | `/skill:emotion-cycle` | 市场情绪冰点 → 回暖 → 狂热 → 退潮周期判断 |
210
+ | 一阳穿三阴 | `/skill:one-yang-three-yin` | K 线形态识别 + 反转信号质量评级 |
211
+ | Wisburg 研报 | `/skill:wisburg-research` | 结构化投研报告生成 |
212
+
213
+ ## 工具列表
214
+
215
+ ### 数据获取
216
+
217
+ | 工具 | 说明 |
218
+ |------|------|
219
+ | `get_kline` | K 线数据(OHLCV),支持日/周/月线 |
220
+ | `get_quote` | 实时行情快照 |
221
+ | `get_capital_flow` | 资金流向(仅 A 股) |
222
+ | `get_news` | 个股相关新闻 |
223
+ | `get_financials` | 财务指标 |
224
+ | `get_stock_info` | 股票基本信息 |
225
+ | `get_chip_distribution` | 筹码分布 |
226
+ | `get_market_indices` | 主要指数行情 |
227
+ | `get_sector_rankings` | 板块涨跌排行 |
228
+ | `get_market_stats` | 市场统计(涨跌家数、涨停等) |
229
+ | `get_fundamental_context` | 基本面综合上下文 |
230
+
231
+ ### 分析计算
232
+
233
+ | 工具 | 说明 |
234
+ |------|------|
235
+ | `get_technical_analysis` | 全面技术指标分析(MA/MACD/RSI/BOLL/KDJ) |
236
+ | `analyze_pattern` | K 线形态识别 |
237
+ | `calculate_ma` | 多周期均线计算 |
238
+ | `get_volume_analysis` | 量价分析 |
239
+ | `evaluate_signal` | 历史信号胜率回测 |
240
+
241
+ ### 筛选与回测
242
+
243
+ | 工具 | 说明 |
244
+ |------|------|
245
+ | `screen_stocks` | 全市场多因子筛选 |
246
+ | `screen_risk` | 风险因子筛查 |
247
+ | `run_backtest` | YAML 策略回测 |
248
+ | `detect_market_regime` | 市场状态检测(牛/熊/震荡) |
249
+
250
+ ### 搜索与舆情
251
+
252
+ | 工具 | 说明 |
253
+ |------|------|
254
+ | `search_stock_news` | 关键词搜索新闻 |
255
+ | `search_comprehensive_intel` | 综合情报搜索 |
256
+ | `get_social_sentiment` | 社交媒体情绪(A 股:东财股吧 + 雪球;美港股:Reddit / X / Polymarket) |
257
+ | `get_trending_sentiment` | 社交媒体热门趋势聚合(Reddit / X / Polymarket,10 分钟缓存) |
258
+ | `extract_article` | 网页正文提取 |
259
+
260
+ ### 辅助
261
+
262
+ | 工具 | 说明 |
263
+ |------|------|
264
+ | `resolve_stock_name` | 股票名称 / 拼音模糊匹配 |
265
+ | `check_trading_day` | 查询是否交易日 |
266
+ | `get_trading_days` | 获取前后 N 个交易日 |
267
+
268
+ ## 策略回测 DSL
269
+
270
+ 策略以 YAML 格式定义,支持参数化和条件组合:
271
+
272
+ ```yaml
273
+ name: "RSI Oversold Bounce"
274
+ version: "1.0"
275
+ description: "RSI超卖反弹策略"
276
+
277
+ parameters:
278
+ rsi_period: 14
279
+ rsi_oversold: 30
280
+ rsi_overbought: 70
281
+ stop_loss: -0.05
282
+ take_profit: 0.15
283
+
284
+ entry:
285
+ conditions:
286
+ - indicator: "rsi"
287
+ period: "{rsi_period}"
288
+ operator: "<"
289
+ value: "{rsi_oversold}"
290
+ - indicator: "volume_ratio"
291
+ operator: ">"
292
+ value: 1.0
293
+ logic: "all"
294
+
295
+ exit:
296
+ conditions:
297
+ - indicator: "rsi"
298
+ period: "{rsi_period}"
299
+ operator: ">"
300
+ value: "{rsi_overbought}"
301
+ logic: "any"
302
+ stop_loss: "{stop_loss}"
303
+ take_profit: "{take_profit}"
304
+
305
+ position:
306
+ size: 1.0
307
+ max_positions: 1
308
+ ```
309
+
310
+ ### 可用指标
311
+
312
+ | 指标 | 说明 | 需要 period |
313
+ |------|------|-------------|
314
+ | `rsi` | RSI 相对强弱指数 | 是(默认 14) |
315
+ | `ma` / `ema` | 简单 / 指数移动平均 | 是(默认 20) |
316
+ | `macd_dif` / `macd_dea` / `macd` | MACD 三线 | 否 |
317
+ | `volume_ratio` | 量比 | 是(默认 5) |
318
+ | `price_change` | 涨跌幅(%) | 否 |
319
+ | `bollinger_position` | 布林带位置(0=下轨, 1=上轨) | 是(默认 20) |
320
+ | `close` / `volume` | 收盘价 / 成交量 | 否 |
321
+
322
+ ### 可用运算符
323
+
324
+ `>` `<` `>=` `<=` `==` `cross_above`(上穿) `cross_below`(下穿)
325
+
326
+ 示例策略见 `strategies/examples/`。
327
+
328
+ ## 市场路由规则
329
+
330
+ | 代码格式 | 示例 | 市场 | 数据源 Failover 链 |
331
+ |----------|------|------|---------------------|
332
+ | 6 位纯数字 | `600519`, `000001`, `300750` | A 股 | akshare → tushare → efinance → pytdx → baostock |
333
+ | 6 位纯数字(51/52/56/58/15/16/18 开头) | `510300`, `159915` | A 股 ETF | akshare(基金接口)→ tushare → efinance → pytdx → baostock |
334
+ | `.HK` 结尾 | `00700.HK`, `09988.HK` | 港股 | yfinance → finnhub → longbridge |
335
+ | 英文字母 | `AAPL`, `GOOGL`, `TSLA` | 美股 | yfinance → finnhub → longbridge → alphavantage |
336
+ | `.T` 结尾 | `7203.T` | 日股 | yfinance |
337
+ | `.KS` / `.KQ` 结尾 | `005930.KS`, `035720.KQ` | 韩股 | yfinance |
338
+ | `.TW` / `.TWO` 结尾 | `2330.TW`, `6510.TWO` | 台股 | yfinance |
339
+
340
+ > 各数据源按优先级自动尝试,前一个失败后自动切换到下一个。未配置相关 env var 的数据源会被跳过。
341
+ > 日/韩/台股仅 yfinance 一个数据源(免费数据延迟约 15 分钟);港股 / 美股 / 日股 / 韩股 / 台股的 ETF 与其所在市场股票走相同链路。
342
+
343
+ ## 独立 CLI 使用
344
+
345
+ Python 工具可脱离 Agent 独立使用,所有输出为 JSON:
346
+
347
+ ```bash
348
+ # 行情数据
349
+ python tools/stock_data.py kline 600519
350
+ python tools/stock_data.py kline AAPL --period weekly --count 30
351
+ python tools/stock_data.py quote 600519
352
+ python tools/stock_data.py capital_flow 600519
353
+ python tools/stock_data.py news 600519 --days 5
354
+ python tools/stock_data.py financials AAPL
355
+
356
+ # 技术分析
357
+ python tools/technical.py analyze 600519
358
+ python tools/technical.py analyze AAPL --period weekly
359
+
360
+ # 全市场筛选
361
+ python tools/screener.py screen --market A --top 20
362
+ python tools/screener.py screen --market A --config my_filter.yaml
363
+
364
+ # 策略回测
365
+ python tools/backtest.py run strategies/examples/rsi_oversold.yaml 600519
366
+ python tools/backtest.py run strategies/examples/rsi_oversold.yaml 600519 --start 2024-01-01 --end 2025-01-01
367
+
368
+ # 搜索与舆情
369
+ python tools/search_intel.py search "茅台 业绩"
370
+ python tools/search_intel.py comprehensive 600519
371
+ python tools/search_intel.py sentiment 600519
372
+ python tools/search_intel.py sentiment AAPL
373
+ python tools/search_intel.py trending
374
+
375
+ # 风险筛查
376
+ python tools/risk_screening.py screen 600519
377
+
378
+ # 市场状态
379
+ python tools/market_regime.py detect A
380
+ ```
381
+
382
+ ## 项目结构
383
+
384
+ ```
385
+ stock-analysis/
386
+ ├── pi/ # Pi Agent Extension
387
+ │ └── index.ts # 注册 39 个工具 + 20 个 skill
388
+ ├── hermes/ # Hermes Agent Plugin
389
+ │ ├── plugin.yaml # 插件清单
390
+ │ ├── __init__.py # register(ctx) 入口
391
+ │ ├── schemas.py # 工具 JSON Schema 定义
392
+ │ └── tools.py # 39 个 handler → subprocess 调 CLI
393
+ ├── openclaw/ # OpenClaw Plugin
394
+ │ ├── openclaw.plugin.json # manifest(contracts.tools)
395
+ │ ├── package.json # 含 openclaw 块(pluginApi/SDK 版本)
396
+ │ └── index.ts # definePluginEntry + registerTool ×39
397
+ ├── dsh/ # DeepSeek Harness (dsh) Plugin
398
+ │ ├── cordis.patch.yml # bundle patch(insert 插件入口)
399
+ │ ├── package.json # 含 dsh.bundle 块(bundle manifest)
400
+ │ └── index.ts # cordis apply(ctx) + defineTool ×39
401
+ │
402
+ ├── tools/ # 共享 Python CLI 工具(12 个脚本)
403
+ │ ├── stock_data.py # 行情 / 资金流 / 新闻 / 财务
404
+ │ ├── technical.py # 技术指标分析
405
+ │ ├── pattern.py # K 线形态识别
406
+ │ ├── screener.py # 全市场多因子筛选
407
+ │ ├── backtest.py # 策略回测引擎
408
+ │ ├── volume_analysis.py # 量价分析
409
+ │ ├── search_intel.py # 搜索 / 舆情 / 正文提取
410
+ │ ├── risk_screening.py # 风险因子筛查
411
+ │ ├── market_regime.py # 市场状态检测
412
+ │ ├── name_resolver.py # 股票名称模糊匹配
413
+ │ ├── trading_calendar.py # 交易日历
414
+ │ └── requirements.txt
415
+ │
416
+ ├── skills/ # 共享 SKILL.md(20 个)
417
+ │ ├── stock-analysis/ # 综合分析 workflow
418
+ │ ├── stock-screener/ # 选股 workflow
419
+ │ ├── strategy-backtest/ # 回测 + 进化 workflow
420
+ │ └── ... # 12 个策略方法论
421
+ │
422
+ ├── strategies/examples/ # 回测策略 YAML 示例
423
+ ├── schemas/ # JSON Schema(研报结构等)
424
+ ├── tests/ # pytest 测试
425
+ ├── package.json # npm / Pi 配置
426
+ └── tsconfig.json
427
+ ```
428
+
429
+ ### 数据流
430
+
431
+ ```
432
+ 用户 (自然语言)
433
+ │
434
+ ▼
435
+ Agent (Pi / Hermes / OpenClaw / dsh)
436
+ │
437
+ ├── 加载 SKILL.md → 分析框架 / 流程指引
438
+ │
439
+ ├── 调用工具 → pi/index.ts 或 hermes/tools.py 或 openclaw/index.ts 或 dsh/index.ts → python3 tools/xxx.py → JSON
440
+ │
441
+ ▼
442
+ Agent (LLM 分析 + 生成报告)
443
+ │
444
+ ▼
445
+ 用户看到结构化分析结果
446
+ ```
447
+
448
+ ## 致谢
449
+
450
+ - [daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis) — A 股每日分析工具,本项目的综合分析流程参考了其设计思路
451
+ - [akshare](https://github.com/akfamily/akshare) — A 股数据源
452
+ - [yfinance](https://github.com/ranaroussi/yfinance) — 港股 / 美股数据源
453
+ - [pytdx](https://github.com/rainx/pytdx) — 通达信 TDX 协议(A 股免费兜底)
454
+ - [longport](https://github.com/longportapp/openapi-sdk) — Longbridge OpenAPI(港股 / 美股)
455
+ - [exchange-calendars](https://github.com/gerrymanoim/exchange_calendars) — 全球交易日历
456
+
457
+ ## 常见问题
458
+
459
+ ### Q: Python 工具报错 `ModuleNotFoundError`?
460
+
461
+ ```bash
462
+ pip install -r tools/requirements.txt
463
+ ```
464
+
465
+ 如果使用 virtualenv / conda,确保 Agent 启动时能访问到对应的 Python 环境。
466
+
467
+ ### Q: A 股数据获取失败?
468
+
469
+ 系统会自动按 akshare → tushare → efinance → pytdx → baostock 顺序尝试。如果所有源都失败,检查:网络问题、akshare 版本过低(`pip install --upgrade akshare`)、或非交易时间。配置 `TUSHARE_TOKEN` 可增加一个可靠数据源。
470
+
471
+ ### Q: 港股 / 美股数据有延迟?
472
+
473
+ yfinance 免费数据通常有 15 分钟延迟。配置 Longbridge(`LONGBRIDGE_APP_KEY` 等)或 Finnhub(`FINNHUB_API_KEY`)可获取更实时的数据,且作为 failover 备用源。
474
+
475
+ ### Q: 如何自定义筛选条件?
476
+
477
+ 创建 YAML 配置:
478
+
479
+ ```yaml
480
+ name: "我的选股策略"
481
+ filters:
482
+ pe_min: 5
483
+ pe_max: 25
484
+ pb_max: 3
485
+ market_cap_min: 20e9
486
+ sort_by: "composite_score"
487
+ sort_order: "desc"
488
+ ```
489
+
490
+ CLI 使用:`python tools/screener.py screen --config my_filter.yaml --top 30`
491
+
492
+ ### Q: 如何编写自定义回测策略?
493
+
494
+ 参考 `strategies/examples/` 下的示例和 [策略回测 DSL](#策略回测-dsl) 章节。也可以直接让 Agent 帮你编写 YAML 策略。
495
+
496
+ ## License
497
+
498
+ MIT
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "stock-analysis-plugin",
3
+ "version": "0.1.10",
4
+ "description": "Pi Agent extension for stock analysis, screening, and strategy backtesting across A/HK/US markets",
5
+ "type": "module",
6
+ "main": "./pi/index.ts",
7
+ "pi": {
8
+ "extensions": [
9
+ "./pi/index.ts"
10
+ ],
11
+ "skills": [
12
+ "./skills/stock-analysis/SKILL.md",
13
+ "./skills/stock-screener/SKILL.md",
14
+ "./skills/strategy-backtest/SKILL.md",
15
+ "./skills/bull-trend/SKILL.md",
16
+ "./skills/shrink-pullback/SKILL.md",
17
+ "./skills/ma-crossover/SKILL.md",
18
+ "./skills/volume-breakout/SKILL.md",
19
+ "./skills/bottom-volume/SKILL.md",
20
+ "./skills/dragon-head/SKILL.md",
21
+ "./skills/chan-theory/SKILL.md",
22
+ "./skills/wave-theory/SKILL.md",
23
+ "./skills/box-oscillation/SKILL.md",
24
+ "./skills/emotion-cycle/SKILL.md",
25
+ "./skills/one-yang-three-yin/SKILL.md",
26
+ "./skills/wisburg-research/SKILL.md",
27
+ "./skills/event-driven/SKILL.md",
28
+ "./skills/expectation-repricing/SKILL.md",
29
+ "./skills/growth-quality/SKILL.md",
30
+ "./skills/hot-theme/SKILL.md",
31
+ "./skills/market-review/SKILL.md"
32
+ ]
33
+ },
34
+ "files": [
35
+ "pi/",
36
+ "tools/**/*.py",
37
+ "tools/requirements.txt",
38
+ "skills/",
39
+ "schemas/",
40
+ "templates/",
41
+ "strategies/",
42
+ "scripts/"
43
+ ],
44
+ "scripts": {
45
+ "postinstall": "node scripts/setup-python.mjs",
46
+ "build:openclaw": "esbuild openclaw/index.ts --bundle --format=esm --platform=node --external:openclaw/* --outfile=openclaw/dist/index.js",
47
+ "build:dsh": "esbuild dsh/index.ts --bundle --format=esm --platform=node --external:@deepseek-ai/* --outfile=dsh/dist/index.js"
48
+ },
49
+ "keywords": [
50
+ "pi-agent",
51
+ "pi-extension",
52
+ "ai-agent",
53
+ "stock",
54
+ "stock-analysis",
55
+ "stock-market",
56
+ "stock-screener",
57
+ "backtest",
58
+ "backtesting",
59
+ "quantitative-finance",
60
+ "quantitative-trading",
61
+ "algorithmic-trading",
62
+ "technical-analysis",
63
+ "factor-investing",
64
+ "a-shares",
65
+ "hk-stocks",
66
+ "us-stocks",
67
+ "akshare",
68
+ "yfinance",
69
+ "tushare"
70
+ ],
71
+ "repository": {
72
+ "type": "git",
73
+ "url": "https://github.com/Weaxs/stock-analysis-plugin"
74
+ },
75
+ "license": "MIT",
76
+ "devDependencies": {
77
+ "@deepseek-ai/cordis": "^4.0.1",
78
+ "@deepseek-ai/dsh-skill": "^0.0.1-rc.1",
79
+ "@deepseek-ai/dsh-tools": "^0.0.1-rc.1",
80
+ "@types/node": "^22.0.0",
81
+ "esbuild": "^0.28.0",
82
+ "jiti": "^2.7.0",
83
+ "openai": "^4.104.0",
84
+ "tsx": "^4.22.1",
85
+ "typebox": "^1.3.10",
86
+ "typescript": "^5.5.0"
87
+ }
88
+ }