feat: 15 nuovi indicatori quant (common + deribit + bybit + macro + sentiment)
Common (mcp_common): - indicators.py: vol_cone, hurst_exponent, half_life_mean_reversion, garch11_forecast, autocorrelation, rolling_sharpe, var_cvar - options.py (nuovo): oi_weighted_skew, smile_asymmetry, atm_vs_wings_vol, dealer_gamma_profile, vanna_charm_aggregate - microstructure.py (nuovo): orderbook_imbalance (ratio + microprice + slope) - stats.py (nuovo): cointegration_test Engle-Granger + ADF helper Deribit (+6 tool MCP): - get_dealer_gamma_profile (net dealer gamma + flip level) - get_vanna_charm (vanna/charm aggregati pesati OI) - get_oi_weighted_skew, get_smile_asymmetry, get_atm_vs_wings_vol - get_orderbook_imbalance Bybit (+2 tool MCP): - get_orderbook_imbalance, get_basis_term_structure (futures dated curve) Macro (+2 tool MCP): - get_yield_curve_slope (2y10y/5y30y + butterfly + regime) - get_breakeven_inflation (FRED T5YIE/T10YIE/T5YIFR) Sentiment (+3 tool MCP): - get_funding_arb_spread (opportunità arb compatte annualizzate) - get_liquidation_heatmap (heuristic da OI delta + funding extreme, no feed paid Coinglass) - get_cointegration_pairs (Engle-Granger su coppie crypto Binance hourly) Tutto in TDD pure-Python (no numpy/scipy in mcp_common). README aggiornato con elenco completo. 442 test totali verdi. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import random
|
||||
|
||||
from mcp_common.stats import cointegration_test
|
||||
|
||||
|
||||
def test_cointegrated_synthetic_pair():
|
||||
"""Costruisco coppia cointegrata: B random walk, A = 2*B + noise stazionario."""
|
||||
r = random.Random(1)
|
||||
b = [100.0]
|
||||
for _ in range(300):
|
||||
b.append(b[-1] + r.gauss(0, 1))
|
||||
a = [2 * b[i] + r.gauss(0, 0.5) for i in range(len(b))]
|
||||
out = cointegration_test(a, b)
|
||||
assert out["cointegrated"] is True
|
||||
assert out["beta"] == pytest_approx(2.0, rel=0.05)
|
||||
assert out["adf_t_stat"] is not None
|
||||
assert out["adf_t_stat"] < -2.86
|
||||
|
||||
|
||||
def test_not_cointegrated_independent_walks():
|
||||
"""Due random walk indipendenti → spread non stazionario → no cointegration."""
|
||||
r = random.Random(2)
|
||||
a = [100.0]
|
||||
b = [100.0]
|
||||
for _ in range(300):
|
||||
a.append(a[-1] + r.gauss(0, 1))
|
||||
b.append(b[-1] + r.gauss(0, 1))
|
||||
out = cointegration_test(a, b)
|
||||
# Per due RW indipendenti, t-stat ADF è solitamente > -2.86 → non cointegrate
|
||||
assert out["cointegrated"] is False or out["adf_t_stat"] > -3.0
|
||||
|
||||
|
||||
def test_cointegration_short_series():
|
||||
out = cointegration_test([1.0, 2.0], [3.0, 4.0])
|
||||
assert out["cointegrated"] is None
|
||||
assert out["beta"] is None
|
||||
|
||||
|
||||
def test_cointegration_mismatched_length():
|
||||
out = cointegration_test([1.0, 2.0, 3.0], [1.0, 2.0])
|
||||
assert out["cointegrated"] is None
|
||||
|
||||
|
||||
def pytest_approx(value, rel):
|
||||
"""Tiny helper to avoid importing pytest just for approx."""
|
||||
class _Approx:
|
||||
def __eq__(self, other):
|
||||
return abs(other - value) <= abs(value) * rel
|
||||
return _Approx()
|
||||
Reference in New Issue
Block a user