COB data and dash
This commit is contained in:
@ -2324,7 +2324,14 @@ class EnhancedTradingOrchestrator:
|
||||
# 4. Return threshold adjustment (0.0 to 0.1 typically)
|
||||
|
||||
# For now, return small adjustment to demonstrate concept
|
||||
if hasattr(self.pivot_rl_trainer.williams, 'cnn_model') and self.pivot_rl_trainer.williams.cnn_model:
|
||||
# Check if CNN models are available in the model registry
|
||||
cnn_available = False
|
||||
for model_key, model in self.model_registry.items():
|
||||
if hasattr(model, 'cnn_model') and model.cnn_model:
|
||||
cnn_available = True
|
||||
break
|
||||
|
||||
if cnn_available:
|
||||
# CNN is available, could provide small threshold reduction for better entries
|
||||
return 0.05 # 5% threshold reduction when CNN available
|
||||
|
||||
@ -2337,17 +2344,27 @@ class EnhancedTradingOrchestrator:
|
||||
def update_dynamic_thresholds(self):
|
||||
"""Update thresholds based on recent performance"""
|
||||
try:
|
||||
# Update thresholds in pivot trainer
|
||||
self.pivot_rl_trainer.update_thresholds_based_on_performance()
|
||||
# Internal threshold update based on recent performance
|
||||
# This orchestrator handles thresholds internally without external trainer
|
||||
|
||||
# Get updated thresholds
|
||||
thresholds = self.pivot_rl_trainer.get_current_thresholds()
|
||||
old_entry = self.entry_threshold
|
||||
old_exit = self.exit_threshold
|
||||
|
||||
self.entry_threshold = thresholds['entry_threshold']
|
||||
self.exit_threshold = thresholds['exit_threshold']
|
||||
self.uninvested_threshold = thresholds['uninvested_threshold']
|
||||
# Simple performance-based threshold adjustment
|
||||
if len(self.completed_trades) >= 10:
|
||||
recent_trades = list(self.completed_trades)[-10:]
|
||||
win_rate = sum(1 for trade in recent_trades if trade.get('pnl_percentage', 0) > 0) / len(recent_trades)
|
||||
|
||||
# Adjust thresholds based on recent performance
|
||||
if win_rate > 0.7: # High win rate - can be more aggressive
|
||||
self.entry_threshold = max(0.5, self.entry_threshold - 0.02)
|
||||
self.exit_threshold = min(0.5, self.exit_threshold + 0.02)
|
||||
elif win_rate < 0.3: # Low win rate - be more conservative
|
||||
self.entry_threshold = min(0.8, self.entry_threshold + 0.02)
|
||||
self.exit_threshold = max(0.2, self.exit_threshold - 0.02)
|
||||
|
||||
# Update uninvested threshold based on activity
|
||||
self.uninvested_threshold = (self.entry_threshold + self.exit_threshold) / 2
|
||||
|
||||
# Log changes if significant
|
||||
if abs(old_entry - self.entry_threshold) > 0.01 or abs(old_exit - self.exit_threshold) > 0.01:
|
||||
@ -2362,9 +2379,32 @@ class EnhancedTradingOrchestrator:
|
||||
trade_outcome: Dict[str, Any]) -> float:
|
||||
"""Calculate reward using the enhanced pivot-based system"""
|
||||
try:
|
||||
return self.pivot_rl_trainer.calculate_pivot_based_reward(
|
||||
trade_decision, market_data, trade_outcome
|
||||
)
|
||||
# Simplified pivot-based reward calculation without external trainer
|
||||
# This orchestrator handles pivot logic internally via dynamic thresholds
|
||||
|
||||
if not trade_outcome or 'pnl_percentage' not in trade_outcome:
|
||||
return 0.0
|
||||
|
||||
pnl_percentage = trade_outcome['pnl_percentage']
|
||||
confidence = trade_decision.get('confidence', 0.5)
|
||||
|
||||
# Base reward from PnL
|
||||
base_reward = pnl_percentage * 10 # Scale PnL to reasonable reward range
|
||||
|
||||
# Bonus for high-confidence decisions that work out
|
||||
confidence_bonus = 0.0
|
||||
if pnl_percentage > 0 and confidence > self.entry_threshold:
|
||||
confidence_bonus = (confidence - self.entry_threshold) * 5.0
|
||||
|
||||
# Penalty for low-confidence losses
|
||||
confidence_penalty = 0.0
|
||||
if pnl_percentage < 0 and confidence < self.exit_threshold:
|
||||
confidence_penalty = abs(pnl_percentage) * 2.0
|
||||
|
||||
total_reward = base_reward + confidence_bonus - confidence_penalty
|
||||
|
||||
return total_reward
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error calculating enhanced pivot reward: {e}")
|
||||
return 0.0
|
||||
|
Reference in New Issue
Block a user