quant-statistics
できること
このスキルは、取引やファクターのリサーチを確認するために使う統計的な検定を、説明し適用します。信頼できる結果が必要な定量アナリスト向けです。
使う場面
- ✓ペア戦略を作る前に、価格系列が定常かどうかを確認したいとき。
- ✓2つの資産が時間を通じて一緒に動くかを検定したいとき。
- ✓ボラティリティをモデル化したり、回帰に統計的な問題がないか確認したりしたいとき。
スキルのリンク
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/quant-statistics/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“ペア戦略を作る前に、これら2つの株価系列が共和分しているかを検定してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、ADF、共和分、GARCH、ブートストラップなどの検定に、すでに用意された関数を使います。公式を書き直すことはしません。必要なライブラリがなければ、インストールすべきものを報告します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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
よくある質問
共和分とは何ですか?
2つの価格系列が、それぞれ勝手に動いても、時間を通じて一緒に動くことを意味します。
追加のライブラリが必要ですか?
一部の検定にはstatsmodelsが必要で、GARCHにはarchパッケージが必要です。スキルは、インストールすべきものを示します。
ADF検定は何を確かめますか?
系列が定常であるか、つまり安定した平均に戻る傾向があるかを確かめます。
詳細
作者による元の説明
Quantitative statistical methods: ADF unit-root / cointegration tests, GARCH volatility modeling, regression diagnostics (heteroskedasticity / autocorrelation), Bootstrap, and hypothesis testing.
repo: HKUDS/Vibe-Trading
人気
- GitHubのスター
- 37k
- ランキング
- #7545
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
vibe-trading
37kバックテスト、ファクター分析、オプション価格、多くの市場にまたがる市場データを含む、金融リサーチの完全なツールキットをエージェントに与えます。
adr-hshare
37k中国企業が複数の市場に上場している価格差、例えば米国のADRと香港株の差を比べる方法をエージェントに示します。
akshare
37kエージェントが、APIキーなしで、中国と世界の株式、先物、外国為替、経済指標の無料の市場データを取得できるよう支援します。
alpha-zoo
37k既製のストックファクターのライブラリを閲覧し、選んだ市場で一群のファクターがリターンをどれだけ予測するかを検証できるよう支援します。
似ているスキル
gitcrawl
394k保存されたGitHubのイシューとプルリクエストのアーカイブを検索し、重複をまとめ、GitHub上の現在の状態を確認するようエージェントを支援します。
slacrawl
394kローカルのSlackアーカイブ内のメッセージを検索して件数を数え、アーカイブの新しさを確認し、必要に応じて更新するようエージェントを支援します。
goplaces
394kGoogle Placesを使って、場所を検索し、詳細や口コミを取得し、場所の名前を解決するようエージェントを支援します。スクリプト用にJSON出力もできます。