Spaces:
Running
Running
Daniel Alnawaz commited on
fixes
Browse files- adaptive_bot.py +9 -2
adaptive_bot.py
CHANGED
|
@@ -331,7 +331,11 @@ class LearningState:
|
|
| 331 |
trade_won = 1 if trade.pnl_usd > 0 else 0
|
| 332 |
# Model predicts p(long wins), so short outcomes must be direction-adjusted.
|
| 333 |
label_long = trade_won if trade.side == "long" else (1 - trade_won)
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
y = np.asarray([label_long], dtype=int)
|
| 336 |
|
| 337 |
# Always update the scaler with new observations (even bootstrap trades).
|
|
@@ -440,7 +444,10 @@ class LearningState:
|
|
| 440 |
"""
|
| 441 |
if not self.model_ready.get(coin):
|
| 442 |
return
|
| 443 |
-
|
|
|
|
|
|
|
|
|
|
| 444 |
x = self.scalers[coin].transform(x_raw) if self.scaler_ready.get(coin) else x_raw
|
| 445 |
x = self.poly.transform(x)
|
| 446 |
sw = np.array([_VIRTUAL_SAMPLE_WEIGHT])
|
|
|
|
| 331 |
trade_won = 1 if trade.pnl_usd > 0 else 0
|
| 332 |
# Model predicts p(long wins), so short outcomes must be direction-adjusted.
|
| 333 |
label_long = trade_won if trade.side == "long" else (1 - trade_won)
|
| 334 |
+
# Pad to NUM_FEATURES in case features were stored with an older (shorter) feature set.
|
| 335 |
+
feat_padded = list(entry_features[:NUM_FEATURES])
|
| 336 |
+
if len(feat_padded) < NUM_FEATURES:
|
| 337 |
+
feat_padded.extend([0.0] * (NUM_FEATURES - len(feat_padded)))
|
| 338 |
+
x_raw = np.asarray(feat_padded, dtype=float).reshape(1, -1)
|
| 339 |
y = np.asarray([label_long], dtype=int)
|
| 340 |
|
| 341 |
# Always update the scaler with new observations (even bootstrap trades).
|
|
|
|
| 444 |
"""
|
| 445 |
if not self.model_ready.get(coin):
|
| 446 |
return
|
| 447 |
+
feat_padded = list(features[:NUM_FEATURES])
|
| 448 |
+
if len(feat_padded) < NUM_FEATURES:
|
| 449 |
+
feat_padded.extend([0.0] * (NUM_FEATURES - len(feat_padded)))
|
| 450 |
+
x_raw = np.asarray(feat_padded, dtype=float).reshape(1, -1)
|
| 451 |
x = self.scalers[coin].transform(x_raw) if self.scaler_ready.get(coin) else x_raw
|
| 452 |
x = self.poly.transform(x)
|
| 453 |
sw = np.array([_VIRTUAL_SAMPLE_WEIGHT])
|