Skip to content
Agentmart
Submit a tool

a-share-pairs-trading

A股配对交易/统计套利分析。当用户说"配对交易"、"pairs trading"、"统计套利"、"价差交易"、"XX和YY能配对吗"、"协整"、"spread"、"套利"时触发。基于 cn-stock-data…

Skill by aifinlab

IndexedApache-2.0★ 261
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/aifinlab-a-share-pairs-trading

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

A股配对交易/统计套利分析。当用户说"配对交易"、"pairs trading"、"统计套利"、"价差交易"、"XX和YY能配对吗"、"协整"、"spread"、"套利"时触发。基于 cn-stock-data 获取双标的K线数据,进行协整检验、价差分析、交易信号生成。支持研报风格(formal)和快速分析风格(brief)。

Use cases: data, finance

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Python package

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/a-share-pairs-trading

What's inside

Skill name
a-share-pairs-trading
Description
A股配对交易/统计套利分析。当用户说"配对交易"、"pairs trading"、"统计套利"、"价差交易"、"XX和YY能配对吗"、"协整"、"spread"、"套利"时触发。基于 cn-stock-data 获取双标的K线数据,进行协整检验、价差分析、交易信号生成。支持研报风格(formal)和快速分析风格(brief)。
License
Apache-2.0
Instructions
77 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Files (3)

  • SKILL.md
  • pairs-trading-guide.md · references/
  • pairs_analyzer.py · scripts/

SKILL.md (first lines)

# A股配对交易分析

## 数据源
```bash
SCRIPTS="$SKILLS_ROOT/cn-stock-data/scripts"
# 两只股票的K线
python "$SCRIPTS/cn_stock_data.py" kline --code [CODE1] --freq daily --start [日期]
python "$SCRIPTS/cn_stock_data.py" kline --code [CODE2] --freq daily --start [日期]
# 行情
python "$SCRIPTS/cn_stock_data.py" quote --code [CODE1],[CODE2]
```

**量化计算**:
```bash
QSCRIPTS="$SKILLS_ROOT/a-share-pairs-trading/scripts"
python "$QSCRIPTS/pairs_analyzer.py" --stock1 data1.json --stock2 data2.json --window 60
```

## Workflow

### Step 1: 选择配对标的
- 同行业/同概念板块优先(基本面相似性)
- 历史价格相关性 > 0.8 作为初筛条件

### Step 2: 协整检验
1. ADF 检验两个价格序列的平稳性(应为 I(1))
2. Engle-Granger 两步法:OLS 回归 → 残差 ADF 检验
3. p-value < 0.05 认为存在协整关系

### Step 3: 价差序列构建
- 方法 A:对数价格比 ln(P1/P2)
- 方法 B:OLS 残差法 P1 - β×P2 - α
- 计算 Z-score = (spread - mean) / std

### Step 4: 交易信号
- 开多价差:Z-score < -2(价差偏低)
- 开空价差:Z-score > +2(价差偏高)
- 平仓:Z-score 回归至 0 附近(±0.5)
- 止损:Z-score 超过 ±3

### Step 5: 输出

| 维度 | formal | brief |
|------|--------|-------|
| 协整检验 | 完整统计量+p值 | 结论(是/否) |
| 价差分析 | 时序图+分布 | 当前 Z-score |
| 回测 | 完整绩效指标 | 年化收益+夏普 |
| 半衰期 | OU 模型详细 | 天数 |

默认风格:brief。

## 关键规则
1. A 股 T+1 限制:当日买入次日才能卖出,配对交易需考虑此约束
2. 涨跌停:一方涨停另一方未涨停会导致价差异常扩大
3. 停牌风险:一方停牌导致无法对冲
4. 协整关系可能失效——需定期检验,建议滚动窗口
5. 交易成本:双边交易成本约 0.2%,需纳入回测

## 使用示例

### 示例 1: 基本使用

```python
# 调用 skill
result = run_skill({
    "param1": "value1",
    "param2": "value2"
})
```

### 示例 2: 命令行使用

```bash
python scripts/run_skill.py --input data.json
```

From aifinlab/FinClaw, Apache-2.0.

More from aifinlab/FinClaw

Signals

Stars
261
Forks
39
Open issues
2
Last commit (this folder)
Mar 26, 2026 (7 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
Apache-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from aifinlab

Cite this page

a-share-pairs-trading skill. Agent Mart. https://agentmart.dev/skills/aifinlab-a-share-pairs-trading (last updated 2026-10-24)