more elaborate RL training

This commit is contained in:
Dobromir Popov
2025-09-09 03:33:49 +03:00
parent 8c17082643
commit 17e18ae86c
2 changed files with 782 additions and 91 deletions

View File

@@ -331,8 +331,39 @@ class ExtremaTrainer:
# Get all available price data for better extrema detection
all_candles = list(self.context_data[symbol].candles)
prices = [candle['close'] for candle in all_candles]
timestamps = [candle['timestamp'] for candle in all_candles]
prices = []
timestamps = []
for i, candle in enumerate(all_candles):
# Handle different candle formats
if isinstance(candle, dict):
if 'close' in candle:
prices.append(candle['close'])
else:
# Fallback to other price fields
price = candle.get('price') or candle.get('high') or candle.get('low') or candle.get('open') or 0
prices.append(price)
# Handle timestamp with fallbacks
if 'timestamp' in candle:
timestamps.append(candle['timestamp'])
elif 'time' in candle:
timestamps.append(candle['time'])
else:
# Generate timestamp based on index if none available
timestamps.append(datetime.now() - timedelta(minutes=len(all_candles) - i))
else:
# Handle non-dict candle formats (e.g., tuples, lists)
if hasattr(candle, '__getitem__'):
prices.append(float(candle[3])) # Assume OHLC format: [O, H, L, C]
timestamps.append(datetime.now() - timedelta(minutes=len(all_candles) - i))
else:
# Skip invalid candle data
continue
# Ensure we have enough data
if len(prices) < self.window_size * 3:
return detected
# Use a more sophisticated extrema detection algorithm
window = self.window_size