""" Full dataset comparison: old-ACT (broken) vs FIX (gidx increment for NaN rows). Verifies FIX produces T=2155. """ import sys, math, pathlib import numpy as np import pandas as pd sys.path.insert(0, '/mnt/dolphinng5_predict') sys.path.insert(0, '/mnt/dolphinng5_predict/nautilus_dolphin') print("Importing...", flush=True) from nautilus_dolphin.nautilus.proxy_boost_engine import create_boost_engine print("Import done.", flush=True) PARQUET_DIR = pathlib.Path('/mnt/dolphinng5_predict/vbt_cache') VOL_P60_INWINDOW = 0.00009868 ENG_KWARGS = dict( max_hold_bars=120, min_irp_alignment=0.45, max_leverage=8.0, vel_div_threshold=-0.02, vel_div_extreme=-0.05, min_leverage=0.5, leverage_convexity=3.0, fraction=0.20, fixed_tp_pct=0.0095, stop_pct=1.0, use_direction_confirm=True, dc_lookback_bars=7, dc_min_magnitude_bps=0.75, dc_skip_contradicts=True, dc_leverage_boost=1.0, dc_leverage_reduce=0.5, use_asset_selection=True, use_sp_fees=True, use_sp_slippage=True, sp_maker_entry_rate=0.62, sp_maker_exit_rate=0.50, use_ob_edge=True, ob_edge_bps=5.0, ob_confirm_rate=0.40, lookback=100, use_alpha_layers=True, use_dynamic_leverage=True, seed=42, ) def make_engine(cap=25000.0): return create_boost_engine(mode='d_liq', initial_capital=cap, **ENG_KWARGS) def compute_vol_ok(df): btc_f = df['BTCUSDT'].values.astype('float64') n = len(btc_f) vol_ok = np.zeros(n, dtype=bool) for j in range(50, n): seg = btc_f[max(0, j-50):j] diffs = np.diff(seg) denom = seg[:-1] if np.any(denom == 0): continue v = float(np.std(diffs / denom)) if math.isfinite(v) and v > 0: vol_ok[j] = v > VOL_P60_INWINDOW return vol_ok def run_day(df, date_str, eng, fix_nan_gidx): """fix_nan_gidx=True → increment _global_bar_idx for NaN rows (correct behavior).""" eng.begin_day(date_str) btc_f = df['BTCUSDT'].values.astype('float64') vol_ok = compute_vol_ok(df) trades = 0 data_arr = df.values cols = df.columns.tolist() usdt_cols = [c for c in cols if c.endswith('USDT')] vd_idx = cols.index('vel_div') if 'vel_div' in cols else -1 v50_idx = cols.index('v50_lambda_max_velocity') if 'v50_lambda_max_velocity' in cols else -1 v750_idx = cols.index('v750_lambda_max_velocity') if 'v750_lambda_max_velocity' in cols else -1 i50_idx = cols.index('instability_50') if 'instability_50' in cols else -1 usdt_idxs = [(c, cols.index(c)) for c in usdt_cols] for i in range(len(df)): row_vals = data_arr[i] vd_raw = float(row_vals[vd_idx]) if vd_idx != -1 else float('nan') if not math.isfinite(vd_raw): if fix_nan_gidx: eng._global_bar_idx += 1 continue v750 = float(row_vals[v750_idx]) if v750_idx != -1 and math.isfinite(float(row_vals[v750_idx])) else 0.0 inst50 = float(row_vals[i50_idx]) if i50_idx != -1 and math.isfinite(float(row_vals[i50_idx])) else 0.0 v50 = float(row_vals[v50_idx]) if v50_idx != -1 and math.isfinite(float(row_vals[v50_idx])) else 0.0 prices = {} for sym, ci in usdt_idxs: p = float(row_vals[ci]) if math.isfinite(p) and p > 0: prices[sym] = p prev_pos = eng.position if hasattr(eng, 'pre_bar_proxy_update'): eng.pre_bar_proxy_update(inst50, v750) eng.step_bar( bar_idx=i, vel_div=vd_raw, prices=prices, v50_vel=v50, v750_vel=v750, vol_regime_ok=bool(vol_ok[i]), ) if prev_pos is not None and eng.position is None: trades += 1 eng.end_day() return trades def main(): files = sorted(PARQUET_DIR.glob('*.parquet')) print(f"Days: {len(files)}", flush=True) act_eng = make_engine() fix_eng = make_engine() act_T = fix_T = 0 for pf in files: date_str = pf.stem df = pd.read_parquet(pf) ta = run_day(df, date_str, act_eng, fix_nan_gidx=False) tf = run_day(df, date_str, fix_eng, fix_nan_gidx=True) act_T += ta; fix_T += tf gap = fix_T - act_T print(f"{date_str}: ACT+{ta:3d}(cum={act_T:4d} ${act_eng.capital:8.0f}) " f"FIX+{tf:3d}(cum={fix_T:4d} ${fix_eng.capital:8.0f}) gap={gap:+d}", flush=True) ic = 25000.0 print(f"\nACT: T={act_T}, cap=${act_eng.capital:.2f}, ROI={100*(act_eng.capital/ic-1):.2f}%", flush=True) print(f"FIX: T={fix_T}, cap=${fix_eng.capital:.2f}, ROI={100*(fix_eng.capital/ic-1):.2f}%", flush=True) if __name__ == '__main__': main()