73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
import pandas as pd, numpy as np, glob
|
|
from scipy import stats
|
|
|
|
arm_a = pd.read_parquet('/mnt/d/Resonance_Engine/traj/tension_20260607T130445/arm_A_no_inject.parquet')
|
|
arm_t = pd.read_parquet('/mnt/d/Resonance_Engine/traj/tension_20260607T130445/arm_T_tension.parquet')
|
|
print('rows A/T:', len(arm_a), len(arm_t))
|
|
print('cols:', list(arm_a.columns))
|
|
|
|
tel_cols = [c for c in arm_a.columns if c not in ['minute','arm','snap_age_ms','funding_bps_annual','bs_ratio_signed','activity_excess','cvd_divergence']]
|
|
print('tel:', tel_cols)
|
|
|
|
print()
|
|
print('ARM A drift (thirds):')
|
|
for col in tel_cols:
|
|
s = arm_a[col].dropna()
|
|
n = len(s)
|
|
t1,t2,t3 = s[:n//3].mean(), s[n//3:2*n//3].mean(), s[2*n//3:].mean()
|
|
print(f' {col}: {t1:.3f} / {t2:.3f} / {t3:.3f}')
|
|
|
|
print()
|
|
print('T vs A sigma shift:')
|
|
for col in tel_cols:
|
|
a_std = arm_a[col].std()
|
|
if a_std > 0:
|
|
sig = (arm_t[col].mean()-arm_a[col].mean())/a_std
|
|
print(f' {col}: {sig:+.1f}sigma')
|
|
|
|
print()
|
|
print('Autocorr arm T:')
|
|
for col in ['asymmetry','coherence','vel_max']:
|
|
if col in arm_t.columns:
|
|
s = arm_t[col].dropna()
|
|
print(f' {col}: lag1={s.autocorr(1):.3f} lag10={s.autocorr(10):.3f} lag60={s.autocorr(60):.3f}')
|
|
|
|
files = sorted(glob.glob('/mnt/d/PaperTrader/research/hl_data/minutes/202604*/*.parquet'))
|
|
pdf = pd.concat([pd.read_parquet(f) for f in files], ignore_index=True)
|
|
pdf = pdf[pdf.coin=='BTC'].sort_values('minute').reset_index(drop=True)
|
|
for h in [60,240]:
|
|
pdf[f'fwd_{h}'] = (pdf['mid_price'].shift(-h)/pdf['mid_price']-1).abs()*10000
|
|
|
|
print()
|
|
print('Instantaneous Spearman arm_T vs |ret|:')
|
|
mt = arm_t.merge(pdf[['minute','fwd_60','fwd_240']], on='minute', how='inner')
|
|
for col in tel_cols:
|
|
for fwd in ['fwd_60','fwd_240']:
|
|
m = mt[[col,fwd]].dropna()
|
|
if len(m)<100: continue
|
|
r,p = stats.spearmanr(m[col],m[fwd])
|
|
if abs(r)>0.04:
|
|
print(f' {col} vs {fwd}: r={r:+.4f} p={p:.4e}')
|
|
|
|
print()
|
|
print('Rolling20 Spearman arm_T:')
|
|
for col in ['asymmetry','coherence','vel_max','stress_xy']:
|
|
if col not in mt.columns: continue
|
|
mt[f'{col}_r20'] = mt[col].rolling(20,min_periods=5).mean().shift(1)
|
|
for fwd in ['fwd_60','fwd_240']:
|
|
m = mt[[f'{col}_r20',fwd]].dropna()
|
|
if len(m)<100: continue
|
|
r,p = stats.spearmanr(m[f'{col}_r20'],m[fwd])
|
|
if abs(r)>0.03:
|
|
print(f' {col}_r20 vs {fwd}: r={r:+.4f} p={p:.4e}')
|
|
|
|
print()
|
|
print('Control: arm_A vs |ret|:')
|
|
ma = arm_a.merge(pdf[['minute','fwd_60','fwd_240']], on='minute', how='inner')
|
|
for col in tel_cols:
|
|
m = ma[[col,'fwd_60']].dropna()
|
|
if len(m)<100: continue
|
|
r,p = stats.spearmanr(m[col],m['fwd_60'])
|
|
if abs(r)>0.04:
|
|
print(f' {col} vs fwd_60: r={r:+.4f} p={p:.4e}')
|