new__training

This commit is contained in:
Dobromir Popov
2025-05-24 02:42:11 +03:00
parent b181d11923
commit ef71160282
10 changed files with 1613 additions and 190 deletions

View File

@ -114,6 +114,14 @@ class Config:
'logs': 'logs',
'cache': 'cache',
'plots': 'plots'
},
'training': {
'use_only_real_data': True,
'batch_size': 32,
'learning_rate': 0.001,
'epochs': 100,
'validation_split': 0.2,
'early_stopping_patience': 10
}
}
@ -188,6 +196,18 @@ class Config:
"""Get file paths"""
return self._config.get('paths', {})
@property
def training(self) -> Dict[str, Any]:
"""Training configuration"""
return {
'use_only_real_data': True,
'batch_size': self._config.get('training', {}).get('batch_size', 32),
'learning_rate': self._config.get('training', {}).get('learning_rate', 0.001),
'epochs': self._config.get('training', {}).get('epochs', 100),
'validation_split': self._config.get('training', {}).get('validation_split', 0.2),
'early_stopping_patience': self._config.get('training', {}).get('early_stopping_patience', 10)
}
def get(self, key: str, default: Any = None) -> Any:
"""Get configuration value by key with optional default"""
return self._config.get(key, default)

View File

@ -500,9 +500,38 @@ class DataProvider:
return pd.DataFrame()
def get_current_price(self, symbol: str) -> Optional[float]:
"""Get current price for a symbol"""
with self.data_lock:
return self.current_prices.get(symbol)
"""Get current price for a symbol from latest candle"""
try:
# Try to get from 1s candle first (most recent)
for tf in ['1s', '1m', '5m', '1h']:
df = self.get_latest_candles(symbol, tf, limit=1)
if df is not None and not df.empty:
return float(df.iloc[-1]['close'])
# Fallback to any available data
key = f"{symbol}_{self.timeframes[0]}"
if key in self.historical_data and not self.historical_data[key].empty:
return float(self.historical_data[key].iloc[-1]['close'])
logger.warning(f"No price data available for {symbol}")
return None
except Exception as e:
logger.error(f"Error getting current price for {symbol}: {e}")
return None
def get_price_at_index(self, symbol: str, index: int, timeframe: str = '1m') -> Optional[float]:
"""Get price at specific index for backtesting"""
try:
key = f"{symbol}_{timeframe}"
if key in self.historical_data:
df = self.historical_data[key]
if 0 <= index < len(df):
return float(df.iloc[index]['close'])
return None
except Exception as e:
logger.error(f"Error getting price at index {index}: {e}")
return None
def get_feature_matrix(self, symbol: str, timeframes: List[str] = None,
window_size: int = 20) -> Optional[np.ndarray]: