diff --git a/scripts/surfer/surfer_poc.py b/scripts/surfer/surfer_poc.py index a54d6a2e6..d773d9590 100644 --- a/scripts/surfer/surfer_poc.py +++ b/scripts/surfer/surfer_poc.py @@ -31,7 +31,8 @@ import torch # noqa: E402 DEV = "cuda" if torch.cuda.is_available() else "cpu" DAY_MS = 86_400_000 -STATE = "data/surfer/poc_state.json" +_REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # cwd-independent (cron-safe) +STATE = os.path.join(_REPO, "data/surfer/poc_state.json") CFG = dict( lookback=20, # XS momentum horizon (days) @@ -81,11 +82,11 @@ def compute_weights(close, qvol, days, cfg): sig = trailing(lc, cfg["lookback"]).copy(); sig[~univ] = np.nan wt = xs_weights(sig) # daily target (market-neutral, unit gross) wt = ewma_rows(wt, cfg["smooth_span"]) # smooth - held = wt.copy() # weekly rebalance on calendar day % K - K = cfg["rebal_k"] + held = wt.copy() # weekly rebalance on FIXED calendar phase (day%K==0) + K = cfg["rebal_k"] # epoch day0=Thu → rebalances every Thursday, live-consistent last = 0 for t in range(T): - if days[t] % K == days[0] % K: + if days[t] % K == 0: last = t held[t] = wt[last] return held, univ @@ -234,7 +235,7 @@ def paper(cfg): st["equity"] *= (1.0 + ret) st["log"].append({"day": today, "mark_ret": round(ret, 6), "equity": round(st["equity"], 5)}) # 2) REBALANCE on the weekly boundary - rebal = (st["last_mark_day"] is None) or (today % cfg["rebal_k"] == days[0] % cfg["rebal_k"]) + rebal = (st["last_mark_day"] is None) or (today % cfg["rebal_k"] == 0) # fixed weekly phase (Thursdays) trades = [] if rebal: cur = st["positions"]