본문으로 건너뛰기
Skillpedia
분석 및 스프레드시트37k · #7545

quant-statistics

하는 일

이 스킬은 매매와 팩터 리서치를 점검하는 데 쓰이는 통계 검정을 설명하고 적용합니다. 신뢰할 수 있는 결과가 필요한 계량 분석가를 위한 스킬입니다.

사용하는 경우

  • ✓전략을 시험하기 전에 가격 시계열이 정상성을 갖는지 확인하고 싶을 때.
  • ✓두 자산이 시간이 지나며 함께 움직이는지 검정해야 할 때.
  • ✓변동성을 모델링하거나 회귀분석에 통계적 문제가 있는지 점검하고 싶은 경우.

스킬 링크

https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/quant-statistics/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/quant-statistics/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“페어 전략을 만들기 전에 이 두 주식의 가격 시계열이 공적분 관계인지 검정해 주세요.”

매주 새 스킬 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

자주 묻는 질문

공적분이란 무엇인가요?

두 가격 시계열이 각각 제멋대로 움직여도, 장기적으로는 함께 움직이는 관계를 뜻합니다.

추가 라이브러리가 필요한가요?

일부 검정은 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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬