COB heatmap WIP
This commit is contained in:
@ -173,6 +173,38 @@ class BaseDataInput:
|
||||
break
|
||||
cob_features.extend(ma_features)
|
||||
|
||||
# Add REAL aggregated COB heatmap features to fill remaining COB slots (no synthetic data)
|
||||
# We compute per-bucket means over the most recent window (up to 300s) and a few global stats
|
||||
try:
|
||||
if self.cob_heatmap_values and self.cob_heatmap_prices:
|
||||
z = np.array(self.cob_heatmap_values, dtype=float)
|
||||
if z.ndim == 2 and z.size > 0:
|
||||
# Use up to the last 300 seconds (or whatever is available)
|
||||
window_rows = z[-300:] if z.shape[0] >= 300 else z
|
||||
# Replace NaNs with 0.0 to respect the no-synthetic rule but avoid NaN propagation
|
||||
window_rows = np.nan_to_num(window_rows, nan=0.0, posinf=0.0, neginf=0.0)
|
||||
|
||||
# Per-bucket mean imbalance/liquidity across time
|
||||
per_bucket_mean = window_rows.mean(axis=0).tolist()
|
||||
space_left = 200 - len(cob_features)
|
||||
if space_left > 0 and len(per_bucket_mean) > 0:
|
||||
cob_features.extend(per_bucket_mean[:space_left])
|
||||
|
||||
# If there is still space, add compact global stats over the window
|
||||
space_left = 200 - len(cob_features)
|
||||
if space_left > 0:
|
||||
flat = window_rows.reshape(-1)
|
||||
if flat.size > 0:
|
||||
global_mean = float(np.mean(flat))
|
||||
global_std = float(np.std(flat))
|
||||
global_max = float(np.max(flat))
|
||||
global_min = float(np.min(flat))
|
||||
global_stats = [global_mean, global_std, global_max, global_min]
|
||||
cob_features.extend(global_stats[:space_left])
|
||||
except Exception:
|
||||
# On any error, skip heatmap-derived features (remaining space will be zero-padded below)
|
||||
pass
|
||||
|
||||
# Pad COB features to exactly 200
|
||||
cob_features.extend([0.0] * (200 - len(cob_features)))
|
||||
features.extend(cob_features[:200]) # Ensure exactly 200 COB features
|
||||
|
Reference in New Issue
Block a user