quant-statistics
Skill này làm gì
Skill này giải thích và áp dụng các kiểm định thống kê để kiểm tra nghiên cứu giao dịch và yếu tố. Skill dành cho nhà phân tích định lượng cần kết quả đáng tin cậy.
Khi nào nên dùng
- ✓Khi bạn muốn kiểm tra xem một chuỗi giá có dừng hay không trước khi kiểm thử chiến lược.
- ✓Khi bạn cần kiểm tra xem hai tài sản có chuyển động cùng nhau theo thời gian không.
- ✓Khi bạn muốn mô hình hóa biến động hoặc kiểm tra một hồi quy có vấn đề thống kê không.
Liên kết skill
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/quant-statistics/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Kiểm tra xem hai chuỗi giá cổ phiếu này có đồng liên kết không trước khi tôi xây dựng chiến lược cặp.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill dùng các hàm có sẵn cho những kiểm định như ADF, đồng liên kết, GARCH và bootstrap, thay vì viết lại công thức. Nếu thiếu thư viện cần thiết, nó sẽ báo bạn cần cài thư viện nào.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Quantitative Statistical Methods
Overview
Common statistical methodology used in quantitative investing, covering time-series testing, volatility modeling, regression diagnostics, and statistical inference. Provides the statistical foundation for strategy development and factor research.
Implementation
Every test below is already implemented and unit-tested in src.quantlib.timeseries. Import and call it — do not retype these formulas into throwaway code, which is how sign errors and double-sqrt bugs get into results.
from src.quantlib.timeseries import (
adf_test, cointegration_test, find_hedge_ratio, compute_half_life,
granger_test, fit_garch, heteroscedasticity_test, autocorrelation_test,
vif_test, bootstrap_statistic, bootstrap_sharpe,
)
Optional backends: statsmodels powers everything except the two bootstrap helpers (which are pure numpy); arch powers fit_garch only. Neither is declared as a dependency of vibe-trading-ai, so both are imported lazily inside the functions. Importing the module always works; calling a function whose backend is missing raises an ImportError naming the package and the install command (pip install "statsmodels>=0.14" / pip install "arch>=6.0"). If you hit that error, report it to the user rather than silently substituting a different method.
Time-Series Tests
1. ADF Unit-Root Test (Stationarity Test)
Why it matters: regressing non-stationary series directly can produce spurious regression, making conclusions unreliable.
from src.quantlib.timeseries import adf_test
result = adf_test(prices['close'], significance=0.05)
# {'adf_statistic': -1.23, 'p_value': 0.65, 'lags_used': 4,
# 'is_stationary': False,
# 'critical_values': {'1%': -3.44, '5%': -2.87, '10%': -2.57}}
if not result['is_stationary']:
returns = np.log(prices['close']).diff().dropna()
adf_test(returns) # log returns are normally stationary
Decision rules:
| p-value | Conclusion | Action |
|---|---|---|
| < 0.01 | Strongly stationary | Can be used directly for regression / modeling |
| 0.01-0.05 | Stationary | Usable |
| 0.05-0.10 | Weak evidence | Difference the series and retest |
| > 0.10 | Non-stationary | Must difference or handle with cointegration |
Stationarity of common financial series:
| Series | Typical Result | Treatment |
|---|---|---|
| Price series | Non-stationary (unit root) | Use log returns |
| Log returns | Stationary | Can be used directly |
| PE / PB series | Usually non-stationary | Use changes or logs |
| Volatility series | Usually stationary | Can be used directly |
| Volume | May be non-stationary | Use logs or standardization |
2. Cointegration Test
Purpose: determine whether two non-stationary series share a long-run equilibrium relationship (the foundation of pair trading / statistical arbitrage).
from src.quantlib.timeseries import cointegration_test
result = cointegration_test(prices_a, prices_b, significance=0.05)
# {'test_statistic': -4.52, 'p_value': 0.002, 'is_cointegrated': True,
# 'critical_values': {'1%': -3.90, '5%': -3.34, '10%': -3.05}}
Both legs must be individually non-stationary (check with adf_test first) — cointegration on two already-stationary series is meaningless.
Both legs must also share one index. Two same-length series on different indices raise ValueError rather than being zipped positionally, because a positional join of, say, an A-share calendar against a US one reports cointegration between days that never coexisted. Reindex or inner-join the two legs yourself before calling.
Application in pair trading:
from src.quantlib.timeseries import find_hedge_ratio, compute_half_life
result = find_hedge_ratio(prices_a, prices_b)
# {'hedge_ratio': 2.49, 'intercept': 0.40,
# 'spread_mean': 0.40, 'spread_std': 1.73, 'half_life': 16.7}
spread = prices_a - result['hedge_ratio'] * prices_b
z_score = (spread - result['spread_mean']) / result['spread_std']
# half_life is in observation periods (days for daily bars) and is `inf`
# when the spread does not mean-revert. Sanity-check it before trading:
# a half-life longer than your holding horizon means the spread will not
# close in time, however good the cointegration p-value looks.
compute_half_life(spread)
A perfectly flat leg (a name halted for the whole window) makes the regression
degenerate, so find_hedge_ratio and `compute_half_l
Câu hỏi thường gặp
Đồng liên kết là gì?
Nghĩa là hai chuỗi giá cùng chuyển động theo thời gian, dù mỗi chuỗi có thể tự dao động.
Tôi có cần thư viện bổ sung không?
Một số kiểm định cần statsmodels, còn GARCH cần gói arch. Skill sẽ cho bạn biết cần cài gì.
Kiểm định ADF kiểm tra điều gì?
Nó kiểm tra xem một chuỗi có dừng hay không, tức là có xu hướng quay về một mức trung bình ổn định.
Chi tiết
Mô tả gốc của tác giả
Quantitative statistical methods: ADF unit-root / cointegration tests, GARCH volatility modeling, regression diagnostics (heteroskedasticity / autocorrelation), Bootstrap, and hypothesis testing.
repo: HKUDS/Vibe-Trading
Độ phổ biến
- Sao GitHub
- 37k
- Vị trí xếp hạng
- #7545
- Giấy phép
- MIT
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
vibe-trading
37kCho agent của bạn bộ công cụ nghiên cứu tài chính đầy đủ: backtest, phân tích nhân tố, định giá quyền chọn và dữ liệu thị trường nhiều nước.
adr-hshare
37kChỉ cho agent của bạn cách so sánh giá của một công ty Trung Quốc được niêm yết ở nhiều thị trường, như ADR ở Mỹ và cổ phiếu ở Hồng Kông.
akshare
37kCho agent của bạn lấy dữ liệu thị trường miễn phí: cổ phiếu Trung Quốc và toàn cầu, tương lai, ngoại hối, chỉ số kinh tế, không cần API key.
alpha-zoo
37kCho agent của bạn duyệt thư viện nhân tố cổ phiếu dựng sẵn và kiểm tra cả một nhóm nhân tố dự đoán lợi nhuận tốt đến đâu trên thị trường đã chọn.
Skill tương tự
gitcrawl
394kCho phép agent của bạn tìm trong kho lưu trữ issue và pull request GitHub, gom các mục trùng lặp và kiểm tra trạng thái hiện tại trên GitHub.
slacrawl
394kCho phép agent của bạn tìm và đếm tin nhắn trong kho lưu trữ Slack cục bộ, kiểm tra kho đó mới đến mức nào và làm mới khi cần.
goplaces
394kGiúp agent của bạn tìm địa điểm, lấy chi tiết và đánh giá, và xác định tên địa điểm bằng Google Places, với đầu ra JSON cho script.