suppa09 commited on
Commit
7bc39f6
·
verified ·
1 Parent(s): e95fff7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -1,5 +1,5 @@
1
  """
2
- PolyBloom ML Ensemble Service v14.2 — OMEGA COUNCIL (8 Models)
3
 
4
  FIXES in v14.2 (reviewer-corrected from v14.1):
5
  1. slope_to_direction: per-TF thresholds (5M=0.003, 15M=0.005, 1D=0.018)
@@ -18,6 +18,16 @@ FIXES in v14.2 (reviewer-corrected from v14.1):
18
  Context correction happens at the endpoint level via context_nudge().
19
 
20
  5. Composite NEUTRAL threshold tightened per-TF.
 
 
 
 
 
 
 
 
 
 
21
  """
22
  import os, time, math
23
  from typing import List, Optional, Tuple
@@ -43,7 +53,7 @@ except Exception:
43
  CHRONOS_MODEL = os.environ.get("CHRONOS_MODEL", "amazon/chronos-t5-small")
44
  MOIRAI_MODEL = os.environ.get("MOIRAI_MODEL", "Salesforce/moirai-1.1-R-small")
45
 
46
- app = FastAPI(title="PolyBloom ML Ensemble v14.2", version="14.2.0")
47
  app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
48
 
49
  _chronos = None
@@ -423,7 +433,11 @@ def run_nbeats(closes, horizon):
423
  dominant_freq = np.argmax(np.abs(fft[1:])) + 1
424
  period = 32 / dominant_freq if dominant_freq > 0 else 32
425
  phase = (n % period) / period * 2 * math.pi
426
- seasonal_signal = math.sin(phase + math.pi / 2)
 
 
 
 
427
  else:
428
  seasonal_signal = 0.0; period = 32.0
429
  residual = (closes[-1] - closes[-5]) / closes[-5] if n >= 5 else 0.0
@@ -455,7 +469,7 @@ def health():
455
  "ok": True,
456
  "chronos": CHRONOS_AVAILABLE,
457
  "moirai": MOIRAI_AVAILABLE,
458
- "version": "14.2.0",
459
  "models": list(STATIC_WEIGHTS.keys()),
460
  }
461
 
 
1
  """
2
+ PolyBloom ML Ensemble Service v14.3 — OMEGA COUNCIL (8 Models)
3
 
4
  FIXES in v14.2 (reviewer-corrected from v14.1):
5
  1. slope_to_direction: per-TF thresholds (5M=0.003, 15M=0.005, 1D=0.018)
 
18
  Context correction happens at the endpoint level via context_nudge().
19
 
20
  5. Composite NEUTRAL threshold tightened per-TF.
21
+
22
+ FIX in v14.3:
23
+ 6. N-BEATS structural UP bias removed.
24
+ Root cause: seasonal_signal = math.sin(phase + math.pi/2).
25
+ When n % period ≈ 0 (common at session open), phase ≈ 0 and
26
+ sin(0 + π/2) = 1.0 — a permanent +1 UP bias injected into every
27
+ forecast regardless of actual price structure.
28
+ Fix: use math.sin(phase) — unbiased; averages to 0 over a full cycle.
29
+ The ctx_nudge (max ±0.006%) was far too small to counteract the
30
+ seasonal term's ±3% contribution (seasonal_signal * 0.03 * 100).
31
  """
32
  import os, time, math
33
  from typing import List, Optional, Tuple
 
53
  CHRONOS_MODEL = os.environ.get("CHRONOS_MODEL", "amazon/chronos-t5-small")
54
  MOIRAI_MODEL = os.environ.get("MOIRAI_MODEL", "Salesforce/moirai-1.1-R-small")
55
 
56
+ app = FastAPI(title="PolyBloom ML Ensemble v14.3", version="14.3.0")
57
  app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
58
 
59
  _chronos = None
 
433
  dominant_freq = np.argmax(np.abs(fft[1:])) + 1
434
  period = 32 / dominant_freq if dominant_freq > 0 else 32
435
  phase = (n % period) / period * 2 * math.pi
436
+ # FIX v14.3: removed + math.pi/2 phase offset.
437
+ # The offset caused sin(0+π/2)=1.0 at session open (n%period≈0),
438
+ # injecting a structural +1 UP bias into every N-BEATS forecast.
439
+ # math.sin(phase) is zero-centered over a full cycle.
440
+ seasonal_signal = math.sin(phase)
441
  else:
442
  seasonal_signal = 0.0; period = 32.0
443
  residual = (closes[-1] - closes[-5]) / closes[-5] if n >= 5 else 0.0
 
469
  "ok": True,
470
  "chronos": CHRONOS_AVAILABLE,
471
  "moirai": MOIRAI_AVAILABLE,
472
+ "version": "14.3.0",
473
  "models": list(STATIC_WEIGHTS.keys()),
474
  }
475