longbridge-pairs-trading
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineselongbridge-pairs-trading
longbridge-pairs-trading
Statistical-arbitrage strategy for a pair of correlated securities. Tests for cointegration, estimates hedge ratio, computes spread Z-score, and outputs actionable long/short signals with half-life and position sizing guidance.
Response language: match the user's input language — Simplified Chinese / Traditional Chinese / English.
针对一对相关证券的统计套利策略。检验协整关系、估算对冲比率、计算价差Z值,并输出可执行的多空信号,同时提供半衰期和仓位规模指导。
响应语言:匹配用户输入语言——简体中文 / 繁体中文 / 英文。
When to use
使用场景
- User provides two ticker symbols and asks for pairs trading analysis, spread mean-reversion, cointegration test, or statistical arbitrage.
- Triggers: "MSFT 和 GOOGL 配对交易", "HSBC vs StanChart 协整", "pairs trade AAPL MSFT", "价差均值回归".
- 用户提供两个股票代码,并请求配对交易分析、价差均值回归、协整检验或统计套利相关内容。
- 触发示例:"MSFT 和 GOOGL 配对交易"、"HSBC vs StanChart 协整"、"pairs trade AAPL MSFT"、"价差均值回归"。
Workflow
工作流程
- Fetch 252 daily candles for each symbol:
longbridge kline <SYMBOL_A> --period day --count 252 --format json longbridge kline <SYMBOL_B> --period day --count 252 --format json - Align on , drop unmatched rows (different trading calendars).
time - Cointegration test (Engle-Granger):
- OLS regress on
ln(close_A)→ hedge ratio βln(close_B) - Compute residuals (spread) =
ln(close_A) − β × ln(close_B) - Run ADF test on residuals; if p-value < 0.05, declare cointegrated
- OLS regress
- Spread statistics:
- Spread mean μ, std σ
- Z-score = (spread_current − μ) / σ
- Half-life λ = −ln(2) / OLS_slope of Δspread ~ spread_{t-1} (AR(1))
- Signal:
- Z > 2.0: long spread (buy A, short B scaled by β)
- Z < −2.0: short spread (short A, buy B scaled by β)
- |Z| < 0.5: exit / neutral
- Position sizing: suggest equal-dollar or volatility-scaled sizing; note that execution must be simultaneous.
Run to confirm current flag names before calling.
longbridge kline --help- 获取每个标的的252条日线K线数据:
longbridge kline <SYMBOL_A> --period day --count 252 --format json longbridge kline <SYMBOL_B> --period day --count 252 --format json - 按对齐,删除不匹配的行(不同交易日历导致)。
time - 协整检验(Engle-Granger法):
- 对和
ln(close_A)进行OLS回归 → 得到对冲比率βln(close_B) - 计算残差(价差)=
ln(close_A) − β × ln(close_B) - 对残差进行ADF检验;若p值<0.05,则判定为存在协整关系
- 对
- 价差统计指标:
- 价差均值μ、标准差σ
- Z值 = (当前价差 − μ) / σ
- 半衰期λ = −ln(2) / Δspread ~ spread_{t-1}(AR(1)模型)的OLS斜率
- 交易信号:
- Z > 2.0:做多价差(买入A,按β比例做空B)
- Z < −2.0:做空价差(做空A,按β比例买入B)
- |Z| < 0.5:平仓/中性仓位
- 仓位规模:建议采用等额美元或波动率调整的仓位规模;注意交易需同时执行。
调用前请运行确认当前参数名称。
longbridge kline --helpCLI
CLI命令
bash
longbridge kline --help
longbridge kline <SYMBOL_A> --period day --count 252 --format json
longbridge kline <SYMBOL_B> --period day --count 252 --format jsonbash
longbridge kline --help
longbridge kline <SYMBOL_A> --period day --count 252 --format json
longbridge kline <SYMBOL_B> --period day --count 252 --format jsonOutput
输出内容
| Metric | 简体 | 繁體 | English |
|---|---|---|---|
| Hedge ratio β | 对冲比率 | 對沖比率 | Hedge ratio |
| Cointegration p-value | 协整 p 值 | 協整 p 值 | Cointegration p-value |
| Spread Z-score | 价差 Z 分 | 價差 Z 分 | Spread Z-score |
| Half-life | 半衰期(天) | 半衰期(天) | Half-life (days) |
| Signal | 交易信号 | 交易訊號 | Trade signal |
Output: cointegration verdict → spread statistics table → current signal → position guidance. Add a risk note if p-value > 0.05 (not cointegrated). Cite Longbridge Securities / 数据来源:长桥证券 / 數據來源:長橋證券.
| 指标 | 简体 | 繁体 | English |
|---|---|---|---|
| Hedge ratio β | 对冲比率 | 對沖比率 | Hedge ratio |
| Cointegration p-value | 协整 p 值 | 協整 p 值 | Cointegration p-value |
| Spread Z-score | 价差 Z 分 | 價差 Z 分 | Spread Z-score |
| Half-life | 半衰期(天) | 半衰期(天) | Half-life (days) |
| Signal | 交易信号 | 交易訊號 | Trade signal |
输出顺序:协整判定结果 → 价差统计表格 → 当前交易信号 → 仓位指导。若p值>0.05(无协整关系),需添加风险提示。注明Longbridge Securities / 数据来源:长桥证券 / 數據來源:長橋證券。
Error handling
错误处理
| Situation | 简体回复 | 繁體回復 | English reply |
|---|---|---|---|
| 回退到 MCP 或提示安装 longbridge-terminal | 回退到 MCP 或提示安裝 longbridge-terminal | Fall back to MCP or install longbridge-terminal |
| 请运行 | 請執行 | Run |
| ADF p-value > 0.05 | 两标的未通过协整检验,配对交易风险较高 | 兩標的未通過協整檢驗,配對交易風險較高 | Not cointegrated; pairs trade is high-risk |
| Insufficient overlapping dates | 两标的历史数据重叠不足,无法建立配对 | 兩標的歷史數據重疊不足 | Insufficient overlapping history |
| Other stderr | 直接显示原始错误 | 直接顯示原始錯誤 | Surface verbatim |
| 场景 | 简体回复 | 繁體回復 | English reply |
|---|---|---|---|
| 回退到MCP或提示安装longbridge-terminal | 回退到MCP或提示安裝longbridge-terminal | Fall back to MCP or install longbridge-terminal |
| 请运行 | 請執行 | Run |
| ADF p-value > 0.05 | 两标的未通过协整检验,配对交易风险较高 | 兩標的未通過協整檢驗,配對交易風險較高 | Not cointegrated; pairs trade is high-risk |
| Insufficient overlapping dates | 两标的历史数据重叠不足,无法建立配对 | 兩標的歷史數據重疊不足 | Insufficient overlapping history |
| Other stderr | 直接显示原始错误 | 直接顯示原始錯誤 | Surface verbatim |
MCP fallback
MCP回退方案
Use with , for each symbol when CLI is unavailable.
mcp__longbridge__candlesticksperiod=Daycount=252当CLI不可用时,对每个标的使用,参数设置为、。
mcp__longbridge__candlesticksperiod=Daycount=252Related skills
相关技能
- — raw OHLCV data
longbridge-kline - — correlation matrix and rolling correlation as a pre-screen
longbridge-correlation - — vol context for spread width
longbridge-volatility-strategy
- — 原始OHLCV数据
longbridge-kline - — 相关系数矩阵和滚动相关性(用于预筛选)
longbridge-correlation - — 价差宽度的波动率背景分析
longbridge-volatility-strategy
File layout
文件结构
longbridge-pairs-trading/
└── SKILL.mdlongbridge-pairs-trading/
└── SKILL.md