pairs-trading
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "pairs-trading" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-202ec2abaf63c65b7cad05387fb76dab067cfec0bd9385bb9765ab160e7f6b5c. Verify the upstream source and version against https://skillhub.cn/skills/user_058048a4/pairs-trading before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
A-share pairs trading backtest tool: input two stocks (name or code) to automatically assess pair suitability (correlation, cointegration test, industry match), run a one-year backtest of a mean-reversion strategy based on the 60-day moving average (initial capital 1,000,000, excluding transaction costs), compute returns and provide current position suggestions, and produce an interactive HTML report with spread bands, equity curve, and key metrics. Suitable for quant strategy research, relative-value analysis, and arbitrage backtesting.
Introduction source: third_party · user_058048a4 · 1.0.2 Reference
SkillPi interpretation
- Inputs and outputs
- Translation pending; see source documentation.
- Software, accounts and paid services
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: pairs-trading
slug: pairs-trading
displayName: A股配对交易回测与建议
version: 1.0.1
description: >-
A股配对交易策略回测工具。输入两只股票名称或代码,自动评估配对适应性(相关性、协整检验、行业匹配),
基于60日均线的均值回复策略进行过去一年的配对交易回测,初始资金100万,不含交易费用,
计算回报率并给出当前持仓建议。生成交互式HTML报告,包含价差带图、资产曲线、关键指标。
当用户提到"配对交易""pair trading""统计套利""两只股票比较""价差交易"等需求时触发此技能。
适用于量化策略研究、相对价值分析、套利回测等场景。
agent_created: trueA股配对交易回测 (Pairs Trading Backtest)
功能
输入两只A股名称或代码,自动完成以下流程:
- 配对适应性评估 — 相关性分析、协整检验(Engle-Granger)、行业匹配检查
- 配对交易回测 — 以60日交易均线为均值基准,过去一年的均值回复策略回测
- 绩效报告 — 初始资金100万,不含交易费用,计算年化回报率
- 操作建议 — 对当前价差状况给出交易建议
使用方法
@skill:pairs-trading 贵州茅台 五粮液
@skill:pairs-trading 600519 000858
输出
- 交互式HTML报告,包含:
- 交易策略详解 — 完整的策略逻辑说明(价差构建、均值计算、建仓/平仓信号、资金分配)
- 配对适应性评估结果(相关性、协整检验)
- 归一股价走势图 — 两只股票归一化对比,标注每次建仓、平仓时间点
- 对数价差与交易信号图 — 价差 + 60日均线 + ±2σ交易带 + z-score + 建仓/平仓标注
- 资产净值曲线
- 绩效指标(年化回报、最大回撤、胜率、夏普比率等)
- 当前状况与操作建议
依赖
- akshare: A股行情数据
- numpy/pandas: 数据处理
- scipy: 统计检验
- statsmodels: 协整检验
- plotly: 交互式图表
策略说明
价差构建
对两只股票的收盘价取对数 log(P_A)、log(P_B),用普通最小二乘法(OLS)回归得到对冲比率 β:
价差 = log(P_A) - (α + β·log(P_B))
均值基准
以 60日移动均线 作为价差的均值基准,计算60日滚动标准差 σ:
- 上轨 = 均线 + 2σ
- 下轨 = 均线 - 2σ
建仓信号
计算 z-score = (价差 - 均线) / σ:
- z > +2.0:价差偏高 → 做多 B(便宜),融券做空 A(贵)
- z < -2.0:价差偏低 → 做多 A(便宜),融券做空 B(贵)
平仓信号
z-score 回归穿过零轴时平仓(价差回归均值时获利了结)。回测期末仍有持仓则强制平仓。
资金分配
- 100% 资金用于做多,多头持仓作为融券做空的抵押品
- 做空端等额匹配(与多头同等金额)
- 空仓期间资金按货币基金年化 2% 计算收益
策略性质
配对交易是一种统计套利策略。基于两只高度相关股票的价差具有均值回复特性:当价差偏离历史均值时建仓,待回归时平仓获利。不对市场方向做判断,收益来源于相对价值的收敛。
Current listing version
1.0.2
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供完整的A股配对交易回测流程,涵盖适应性评估、策略执行、绩效报告与操作建议
- 生成交互式HTML报告,包含价差带图、资产曲线、关键指标,显著提升量化研究效率
- 适用于量化策略研究、相对价值分析、套利回测等明确场景,具备高频刚需属性
Highlights
- 触发词精准完整,覆盖"配对交易""pair trading""统计套利""两只股票比较""价差交易"等多种变体
- 边界清晰,不易与其他Skill重叠
Highlights
- 文档结构完整,包含功能说明、使用方法、输出内容、依赖说明、策略详解
- 策略逻辑清晰,包含价差构建、均值基准、建仓/平仓信号、资金分配等完整闭环
- 提供端到端使用示例,frontmatter完整
Highlights
- 工具来源明确(akshare、numpy/pandas、scipy、statsmodels、plotly),参数定义清晰
- 覆盖主要异常处理(回测期末强制平仓),资金分配逻辑合理
- 策略逻辑闭环,无不可逆操作风险
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Translation pending; see source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.