121 lines
4.4 KiB
Python
121 lines
4.4 KiB
Python
|
|
"""
|
||
|
|
test_gold_fork.py — Definitive D_LIQ_GOLD replication test on agent-forked code.
|
||
|
|
|
||
|
|
Tests the D_LIQ_GOLD engine using the PROVEN run_backtest() path from exp_shared_AGENT_fork.py
|
||
|
|
(exact copy of agent-modified exp_shared.py).
|
||
|
|
|
||
|
|
Gold target: ROI=181.81%, DD=17.65%, Calmar=10.30, T=2155
|
||
|
|
Tolerance: ROI ±2pp, Trades ±5
|
||
|
|
|
||
|
|
Specific agent claims verified here:
|
||
|
|
A. Orchestrator ceiling_lev 6→10 (set_esoteric_hazard_multiplier)
|
||
|
|
B. MC red: proportional 0.80x vs hard 5.0x cap
|
||
|
|
C. exp_shared rolling vol_p60 vs static
|
||
|
|
D. float32 casting, lazy OB loading
|
||
|
|
|
||
|
|
RUNS ON: exp_shared_AGENT_fork.py (do not touch production exp_shared.py)
|
||
|
|
"""
|
||
|
|
import sys, time
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
ROOT = Path(r"C:\Users\Lenovo\Documents\- DOLPHIN NG HD HCM TSF Predict")
|
||
|
|
sys.path.insert(0, str(ROOT / 'nautilus_dolphin'))
|
||
|
|
|
||
|
|
# ── Import the FORKED exp_shared (not the live one) ───────────────────────────
|
||
|
|
import importlib.util, types
|
||
|
|
|
||
|
|
def load_fork(fork_path: Path, module_name: str):
|
||
|
|
spec = importlib.util.spec_from_file_location(module_name, fork_path)
|
||
|
|
mod = importlib.util.module_from_spec(spec)
|
||
|
|
sys.modules[module_name] = mod
|
||
|
|
spec.loader.exec_module(mod)
|
||
|
|
return mod
|
||
|
|
|
||
|
|
print("Loading forked exp_shared...")
|
||
|
|
exp = load_fork(
|
||
|
|
ROOT / 'nautilus_dolphin' / 'dvae' / 'exp_shared_AGENT_fork.py',
|
||
|
|
'exp_shared_fork'
|
||
|
|
)
|
||
|
|
|
||
|
|
from nautilus_dolphin.nautilus.proxy_boost_engine import create_d_liq_engine, LiquidationGuardEngine
|
||
|
|
|
||
|
|
GOLD_ROI = 181.81
|
||
|
|
GOLD_TRADES = 2155
|
||
|
|
GOLD_DD = 17.65
|
||
|
|
GOLD_CALMAR = 10.30
|
||
|
|
TOL_ROI = 2.0 # ±2pp
|
||
|
|
TOL_TRADES = 5 # ±5
|
||
|
|
|
||
|
|
def run_test(label: str, factory, extra_kwargs=None):
|
||
|
|
print(f"\n{'='*60}")
|
||
|
|
print(f" TEST: {label}")
|
||
|
|
print(f"{'='*60}")
|
||
|
|
t0 = time.time()
|
||
|
|
result = exp.run_backtest(factory, label, extra_kwargs=extra_kwargs)
|
||
|
|
elapsed = time.time() - t0
|
||
|
|
|
||
|
|
roi = result['roi']
|
||
|
|
trades = result['trades']
|
||
|
|
dd = result['dd']
|
||
|
|
calmar = result.get('calmar', 0.0)
|
||
|
|
|
||
|
|
roi_ok = abs(roi - GOLD_ROI) <= TOL_ROI
|
||
|
|
trade_ok = abs(trades - GOLD_TRADES) <= TOL_TRADES
|
||
|
|
|
||
|
|
print(f"\n ROI: {roi:+.2f}% (gold={GOLD_ROI:.2f}% diff={roi-GOLD_ROI:+.2f}pp) {'✓' if roi_ok else '✗'}")
|
||
|
|
print(f" Trades: {trades} (gold={GOLD_TRADES} diff={trades-GOLD_TRADES:+d}) {'✓' if trade_ok else '✗'}")
|
||
|
|
print(f" DD: {dd:.2f}% (gold={GOLD_DD:.2f}%)")
|
||
|
|
print(f" Calmar: {calmar:.2f} (gold={GOLD_CALMAR:.2f})")
|
||
|
|
print(f" Time: {elapsed:.0f}s")
|
||
|
|
|
||
|
|
passed = roi_ok and trade_ok
|
||
|
|
print(f"\n VERDICT: {'PASS ✓' if passed else 'FAIL ✗'}")
|
||
|
|
return {'label': label, 'roi': roi, 'trades': trades, 'dd': dd,
|
||
|
|
'calmar': calmar, 'elapsed': elapsed, 'pass': passed}
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
print("\n" + "="*60)
|
||
|
|
print(" D_LIQ_GOLD REPLICATION — AGENT FORK TEST")
|
||
|
|
print(f" Using: exp_shared_AGENT_fork.py")
|
||
|
|
print(f" Gold: ROI={GOLD_ROI}% T={GOLD_TRADES} DD={GOLD_DD}% Calmar={GOLD_CALMAR}")
|
||
|
|
print("="*60)
|
||
|
|
|
||
|
|
print("\nWarming up JIT...")
|
||
|
|
exp.ensure_jit()
|
||
|
|
print(" JIT ready.")
|
||
|
|
|
||
|
|
results = []
|
||
|
|
|
||
|
|
# Test 1: D_LIQ_GOLD — perfect maker (closest to gold certification)
|
||
|
|
results.append(run_test(
|
||
|
|
"D_LIQ_GOLD perfect-maker (fork)",
|
||
|
|
lambda kw: create_d_liq_engine(**kw),
|
||
|
|
extra_kwargs={
|
||
|
|
'sp_maker_entry_rate': 1.0,
|
||
|
|
'sp_maker_exit_rate': 1.0,
|
||
|
|
'use_sp_slippage': False,
|
||
|
|
}
|
||
|
|
))
|
||
|
|
|
||
|
|
# Test 2: D_LIQ_GOLD stochastic (production mode, 0.62 fill)
|
||
|
|
results.append(run_test(
|
||
|
|
"D_LIQ_GOLD stochastic 0.62 (fork)",
|
||
|
|
lambda kw: create_d_liq_engine(**kw),
|
||
|
|
))
|
||
|
|
|
||
|
|
# ── Summary ────────────────────────────────────────────────────────────────
|
||
|
|
print(f"\n{'='*60}")
|
||
|
|
print(" FORK TEST SUMMARY")
|
||
|
|
print(f"{'='*60}")
|
||
|
|
n_pass = sum(1 for r in results if r['pass'])
|
||
|
|
for r in results:
|
||
|
|
status = 'PASS ✓' if r['pass'] else 'FAIL ✗'
|
||
|
|
print(f" {status} {r['label']:<40} ROI={r['roi']:+.2f}% T={r['trades']} Calmar={r['calmar']:.2f}")
|
||
|
|
print(f"\n {n_pass}/{len(results)} tests passed")
|
||
|
|
|
||
|
|
if n_pass == len(results):
|
||
|
|
print("\n ✓ AGENT CHANGES VERIFIED — D_LIQ_GOLD REPLICATES ON FORK")
|
||
|
|
else:
|
||
|
|
print("\n ✗ REPLICATION FAILURE — agent changes compromise gold standard")
|