pivot improvement
This commit is contained in:
@ -55,6 +55,7 @@ try:
|
||||
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
|
||||
from core.universal_data_adapter import UniversalDataAdapter
|
||||
from core.unified_data_stream import UnifiedDataStream, TrainingDataPacket, UIDataPacket
|
||||
from training.enhanced_pivot_rl_trainer import EnhancedPivotRLTrainer, create_enhanced_pivot_trainer
|
||||
ENHANCED_RL_AVAILABLE = True
|
||||
logger.info("Enhanced RL training components available")
|
||||
except ImportError as e:
|
||||
@ -360,6 +361,20 @@ class TradingDashboard:
|
||||
except ImportError:
|
||||
self.williams_structure = None
|
||||
logger.warning("Williams Market Structure not available")
|
||||
|
||||
# Initialize Enhanced Pivot RL Trainer for better position management
|
||||
try:
|
||||
self.pivot_rl_trainer = create_enhanced_pivot_trainer(
|
||||
data_provider=self.data_provider,
|
||||
orchestrator=self.orchestrator
|
||||
)
|
||||
logger.info("Enhanced Pivot RL Trainer initialized for better entry/exit decisions")
|
||||
logger.info(f"Entry threshold: {self.pivot_rl_trainer.get_current_thresholds()['entry_threshold']:.1%}")
|
||||
logger.info(f"Exit threshold: {self.pivot_rl_trainer.get_current_thresholds()['exit_threshold']:.1%}")
|
||||
logger.info(f"Uninvested threshold: {self.pivot_rl_trainer.get_current_thresholds()['uninvested_threshold']:.1%}")
|
||||
except Exception as e:
|
||||
self.pivot_rl_trainer = None
|
||||
logger.warning(f"Enhanced Pivot RL Trainer not available: {e}")
|
||||
|
||||
def _to_local_timezone(self, dt: datetime) -> datetime:
|
||||
"""Convert datetime to configured local timezone"""
|
||||
@ -4358,7 +4373,47 @@ class TradingDashboard:
|
||||
return False
|
||||
|
||||
def _calculate_rl_reward(self, closed_trade):
|
||||
"""Calculate enhanced reward for RL training with proper penalties for losing trades"""
|
||||
"""Calculate enhanced reward for RL training using pivot-based system"""
|
||||
try:
|
||||
# Extract trade information
|
||||
trade_decision = {
|
||||
'action': closed_trade.get('side', 'HOLD'),
|
||||
'confidence': closed_trade.get('confidence', 0.5),
|
||||
'price': closed_trade.get('entry_price', 0.0),
|
||||
'timestamp': closed_trade.get('entry_time', datetime.now())
|
||||
}
|
||||
|
||||
trade_outcome = {
|
||||
'net_pnl': closed_trade.get('net_pnl', 0),
|
||||
'exit_price': closed_trade.get('exit_price', 0.0),
|
||||
'duration': closed_trade.get('duration', timedelta(0))
|
||||
}
|
||||
|
||||
# Get market data context for pivot analysis
|
||||
symbol = closed_trade.get('symbol', 'ETH/USDT')
|
||||
trade_time = trade_decision['timestamp']
|
||||
market_data = self._get_training_context_data(symbol, trade_time, lookback_minutes=120)
|
||||
|
||||
# Use enhanced pivot-based reward if orchestrator is available
|
||||
if hasattr(self, 'orchestrator') and self.orchestrator and hasattr(self.orchestrator, 'calculate_enhanced_pivot_reward'):
|
||||
enhanced_reward = self.orchestrator.calculate_enhanced_pivot_reward(
|
||||
trade_decision, market_data, trade_outcome
|
||||
)
|
||||
|
||||
# Log the enhanced reward
|
||||
logger.info(f"[ENHANCED_REWARD] Using pivot-based reward: {enhanced_reward:.3f}")
|
||||
return enhanced_reward
|
||||
|
||||
# Fallback to original reward calculation if enhanced system not available
|
||||
logger.warning("[ENHANCED_REWARD] Falling back to original reward calculation")
|
||||
return self._calculate_original_rl_reward(closed_trade)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error calculating enhanced RL reward: {e}")
|
||||
return self._calculate_original_rl_reward(closed_trade)
|
||||
|
||||
def _calculate_original_rl_reward(self, closed_trade):
|
||||
"""Original RL reward calculation as fallback"""
|
||||
try:
|
||||
net_pnl = closed_trade.get('net_pnl', 0)
|
||||
duration = closed_trade.get('duration', timedelta(0))
|
||||
@ -4419,7 +4474,7 @@ class TradingDashboard:
|
||||
return reward
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error calculating RL reward: {e}")
|
||||
logger.warning(f"Error calculating original RL reward: {e}")
|
||||
return 0.0
|
||||
|
||||
def _execute_rl_training_step(self, training_episode):
|
||||
|
Reference in New Issue
Block a user