Aller au contenu
Skillpedia
Analyse et tableurs37k · #7545

quant-statistics

Ce qu’il fait

Cette compétence explique et applique les tests statistiques qui vérifient la recherche en trading et en facteurs. Elle s'adresse aux analystes quantitatifs qui ont besoin de résultats fiables.

Quand l’utiliser

  • ✓Quand vous voulez vérifier qu'une série de prix est stationnaire avant de tester une stratégie.
  • ✓Quand vous voulez tester si deux actifs évoluent ensemble dans le temps.
  • ✓Quand vous voulez modéliser la volatilité ou vérifier une régression pour des problèmes statistiques.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/quant-statistics/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Teste si ces deux séries de cours d'actions sont cointégrées avant que je construise une stratégie de paires.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

Elle utilise des fonctions prêtes à l'emploi pour des tests comme l'ADF, la cointégration, le GARCH et le bootstrap, au lieu de réécrire les formules. Si une bibliothèque nécessaire manque, elle indique laquelle installer.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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

Questions fréquentes

Qu'est-ce que la cointégration ?

Deux séries de prix sont cointégrées lorsqu'elles évoluent ensemble dans le temps, même si chacune dérive de son côté.

Faut-il des bibliothèques supplémentaires ?

Certains tests demandent statsmodels, et le GARCH demande le paquet arch. La compétence indique lequel installer.

Que vérifie le test ADF ?

Il vérifie si une série est stationnaire, c'est-à-dire si elle tend à revenir vers une moyenne stable.

Détails

Description originale de l’auteur

Quantitative statistical methods: ADF unit-root / cointegration tests, GARCH volatility modeling, regression diagnostics (heteroskedasticity / autocorrelation), Bootstrap, and hypothesis testing.

repo: HKUDS/Vibe-Trading

Popularité

Étoiles GitHub
37k
Position au classement
#7545
Licence
MIT
Mis à jour
01/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires