Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
One-line summary: Analyze financial time series with GARCH volatility models, cointegration tests, pairs trading signals, Fama-French factor regressions, and rolling risk decomposition.
When to Use This Skill
When modeling volatility clustering with GARCH/EGARCH models
When testing and exploiting cointegration for pairs trading
When running Fama-French 3/5 factor regressions for alpha/beta
When computing rolling VaR, expected shortfall, and drawdowns
When detecting structural breaks in financial time series
When building momentum and mean-reversion trading signals
Trigger keywords: GARCH, volatility, cointegration, pairs trading, Fama-French, factor model, VaR, expected shortfall, momentum, mean reversion, financial time series, ARCH, unit root, ADF test, Kalman filter
Two I(1) series $X_t, Y_t$ are cointegrated if $\exists \beta: Y_t - \beta X_t = u_t$ where $u_t$ is I(0). The spread $u_t$ is mean-reverting and exploitable for pairs trading.
import numpy as np
import pandas as pd
from arch import arch_model
from statsmodels.tsa.stattools import adfuller
# Quick test with synthetic data
np.random.seed(42)
returns = np.random.randn(500) * 0.01
am = arch_model(returns, vol=, p=, q=)
res = am.fit(disp=)
()
'Garch'
1
1
'off'
print
f"arch version OK; GARCH omega={res.params['omega']:.6f}"
Example 1: Value-at-Risk via Historical Simulation
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
np.random.seed(42)
# Simulate portfolio returns (fat-tailed)from scipy.stats import t as t_dist
returns = t_dist.rvs(df=5, size=1000) * 0.01# Historical VaR
confidence = 0.99
var_99 = np.percentile(returns, (1-confidence)*100)
es_99 = returns[returns <= var_99].mean()
print(f"1-day VaR (99%): {var_99*100:.3f}%")
print(f"1-day ES (99%): {es_99*100:.3f}%")
fig, ax = plt.subplots(figsize=(9, 4))
ax.hist(returns*100, bins=50, color='steelblue', edgecolor='white', linewidth=0.5, alpha=0.7)
ax.axvline(var_99*100, color='red', linewidth=2, linestyle='--', label=f'VaR(99%)={var_99*100:.2f}%')
ax.axvline(es_99*100, color='orange', linewidth=2, linestyle='--', label=f'ES(99%)={es_99*100:.2f}%')
ax.set_xlabel("Daily Return (%)"); ax.set_title("Portfolio Return Distribution — VaR / ES")
ax.legend(); ax.grid(alpha=0.3)
plt.tight_layout(); plt.savefig("var_es.png", dpi=150); plt.show()
Example 2: Hurst Exponent (Long Memory Detection)
import numpy as np
defhurst_exponent(ts, max_lag=100):
"""Estimate Hurst exponent via R/S analysis."""
lags = range(2, max_lag)
tau = []
for lag in lags:
n_blocks = len(ts) // lag
if n_blocks < 2:
break
rs_values = []
for i inrange(n_blocks):
block = ts[i*lag:(i+1)*lag]
mean_b = np.mean(block)
dev = np.cumsum(block - mean_b)
R = dev.max() - dev.min()
S = np.std(block, ddof=1)
if S > 0:
rs_values.append(R/S)
if rs_values:
tau.append((lag, np.mean(rs_values)))
lags_arr = np.array([x[0] for x in tau])
rs_arr = np.array([x[1] for x in tau])
H, _ = np.polyfit(np.log(lags_arr), np.log(rs_arr), 1)
return H
np.random.seed(1)
# Compare random walk (H≈0.5) vs. trending (H>0.5)
rw = np.cumsum(np.random.randn(1000)) # Random walk
trending = np.cumsum(np.random.randn(1000) + 0.02) # With driftprint(f"Hurst(random walk): H = {hurst_exponent(rw):.4f} (expected ≈0.5)")
print(f"Hurst(with trend): H = {hurst_exponent(trending):.4f} (expected >0.5)")
Last updated: 2026-03-17 | Maintainer: @xjtulycIssues: GitHub Issues