Spaces:
Running
Running
Upload Quasar_axrvi_ranker.py
Browse files- Quasar_axrvi_ranker.py +20 -5
Quasar_axrvi_ranker.py
CHANGED
|
@@ -392,8 +392,8 @@ GAMMA = 0.99
|
|
| 392 |
LAMBDA_RANK = 0.4
|
| 393 |
LAMBDA_RISK = 0.3
|
| 394 |
REPLAY_CAPACITY = 10_000
|
| 395 |
-
TRAIN_BATCH =
|
| 396 |
-
TRAIN_EVERY_N =
|
| 397 |
|
| 398 |
# Connection
|
| 399 |
WS_RECONNECT_DELAY = 5
|
|
@@ -3394,7 +3394,11 @@ class HybridTrainer:
|
|
| 3394 |
and "selected_idx" in ep and "pnl_per_asset" in ep
|
| 3395 |
]
|
| 3396 |
if not valid:
|
| 3397 |
-
logger.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3398 |
return {}
|
| 3399 |
|
| 3400 |
self.model.train()
|
|
@@ -5280,8 +5284,17 @@ class QuasarAXRVIBridge:
|
|
| 5280 |
self.portfolio_risk_mgr.register_open(trade_id, quantity * price)
|
| 5281 |
|
| 5282 |
# [S2] Capture s_t ∈ F_t at the moment of trade open
|
| 5283 |
-
|
| 5284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5285 |
# [S8] Initialise tick counter for optimal-stopping monitor
|
| 5286 |
self._trade_tick_counts[trade_id] = 0
|
| 5287 |
|
|
@@ -7274,6 +7287,8 @@ if __name__ == "__main__":
|
|
| 7274 |
model_path = args.model,
|
| 7275 |
hub_ws_url = args.hub,
|
| 7276 |
enable_logging = not args.no_logs,
|
|
|
|
|
|
|
| 7277 |
))
|
| 7278 |
except KeyboardInterrupt:
|
| 7279 |
print("\n👋 Shutting down…")
|
|
|
|
| 392 |
LAMBDA_RANK = 0.4
|
| 393 |
LAMBDA_RISK = 0.3
|
| 394 |
REPLAY_CAPACITY = 10_000
|
| 395 |
+
TRAIN_BATCH = 4 # FIX 2: Lowered from 8 — fills after ~4 closed trades (~1-2 min)
|
| 396 |
+
TRAIN_EVERY_N = 3 # FIX 2: Lowered from 5 — checks buffer every ~15s
|
| 397 |
|
| 398 |
# Connection
|
| 399 |
WS_RECONNECT_DELAY = 5
|
|
|
|
| 3394 |
and "selected_idx" in ep and "pnl_per_asset" in ep
|
| 3395 |
]
|
| 3396 |
if not valid:
|
| 3397 |
+
logger.warning(
|
| 3398 |
+
f"[HybridTrainer] No valid episodes in batch of {len(episodes)} — "
|
| 3399 |
+
f"skipping training step. Episodes may be missing required keys: "
|
| 3400 |
+
f"'sequences', 'next_sequences', 'selected_idx', 'pnl_per_asset'."
|
| 3401 |
+
)
|
| 3402 |
return {}
|
| 3403 |
|
| 3404 |
self.model.train()
|
|
|
|
| 5284 |
self.portfolio_risk_mgr.register_open(trade_id, quantity * price)
|
| 5285 |
|
| 5286 |
# [S2] Capture s_t ∈ F_t at the moment of trade open
|
| 5287 |
+
# FIX 3: Guard against None — do NOT silently default to index 0,
|
| 5288 |
+
# which would attribute this episode to the wrong asset entirely.
|
| 5289 |
+
if self._last_selected_idx is None:
|
| 5290 |
+
logger.warning(
|
| 5291 |
+
f"[_open_pending_episode] [{asset}] No selected_idx available — "
|
| 5292 |
+
f"skipping episode capture for trade_id={trade_id}. "
|
| 5293 |
+
f"Trade will still execute but will NOT contribute to training."
|
| 5294 |
+
)
|
| 5295 |
+
else:
|
| 5296 |
+
selected_idx = self._last_selected_idx
|
| 5297 |
+
self._open_pending_episode(trade_id, asset, selected_idx)
|
| 5298 |
# [S8] Initialise tick counter for optimal-stopping monitor
|
| 5299 |
self._trade_tick_counts[trade_id] = 0
|
| 5300 |
|
|
|
|
| 7287 |
model_path = args.model,
|
| 7288 |
hub_ws_url = args.hub,
|
| 7289 |
enable_logging = not args.no_logs,
|
| 7290 |
+
checkpoint_dir = args.checkpoint_dir, # FIX 1: was silently ignored
|
| 7291 |
+
resume = args.resume, # FIX 1: was silently ignored
|
| 7292 |
))
|
| 7293 |
except KeyboardInterrupt:
|
| 7294 |
print("\n👋 Shutting down…")
|