loss /performance display
This commit is contained in:
@ -3981,19 +3981,45 @@ class CleanTradingDashboard:
|
||||
async def _on_trading_decision(self, decision):
|
||||
"""Handle trading decision from orchestrator."""
|
||||
try:
|
||||
action = getattr(decision, 'action', decision.get('action'))
|
||||
# Handle both object and dict formats
|
||||
if hasattr(decision, 'action'):
|
||||
action = getattr(decision, 'action', 'HOLD')
|
||||
symbol = getattr(decision, 'symbol', 'ETH/USDT')
|
||||
confidence = getattr(decision, 'confidence', 0.0)
|
||||
else:
|
||||
action = decision.get('action', 'HOLD')
|
||||
symbol = decision.get('symbol', 'ETH/USDT')
|
||||
confidence = decision.get('confidence', 0.0)
|
||||
|
||||
if action == 'HOLD':
|
||||
return
|
||||
symbol = getattr(decision, 'symbol', decision.get('symbol', 'ETH/USDT'))
|
||||
|
||||
if 'ETH' not in symbol.upper():
|
||||
return
|
||||
dashboard_decision = asdict(decision) if not isinstance(decision, dict) else decision.copy()
|
||||
dashboard_decision['timestamp'] = datetime.now()
|
||||
dashboard_decision['executed'] = False
|
||||
|
||||
# Convert to dict format for dashboard storage
|
||||
if hasattr(decision, '__dict__'):
|
||||
dashboard_decision = {
|
||||
'action': action,
|
||||
'symbol': symbol,
|
||||
'confidence': confidence,
|
||||
'timestamp': datetime.now(),
|
||||
'executed': False
|
||||
}
|
||||
# Add any other attributes from the decision object
|
||||
for attr in ['price', 'quantity', 'reasoning', 'model_source']:
|
||||
if hasattr(decision, attr):
|
||||
dashboard_decision[attr] = getattr(decision, attr)
|
||||
else:
|
||||
dashboard_decision = decision.copy()
|
||||
dashboard_decision['timestamp'] = datetime.now()
|
||||
dashboard_decision['executed'] = False
|
||||
|
||||
self.recent_decisions.append(dashboard_decision)
|
||||
if len(self.recent_decisions) > 200:
|
||||
self.recent_decisions.pop(0)
|
||||
logger.info(f"[ORCHESTRATOR SIGNAL] Received: {action} for {symbol}")
|
||||
|
||||
logger.info(f"[ORCHESTRATOR SIGNAL] Received: {action} for {symbol} (confidence: {confidence:.3f})")
|
||||
except Exception as e:
|
||||
logger.error(f"Error handling trading decision: {e}")
|
||||
|
||||
@ -4523,6 +4549,10 @@ class CleanTradingDashboard:
|
||||
network.train()
|
||||
action_logits, predicted_confidence = network(features_tensor)
|
||||
|
||||
# Ensure predicted_confidence has a batch dimension if it doesn't already
|
||||
if predicted_confidence.dim() == 0:
|
||||
predicted_confidence = predicted_confidence.unsqueeze(0)
|
||||
|
||||
# Calculate losses
|
||||
action_loss = nn.CrossEntropyLoss()(action_logits, action_target_tensor)
|
||||
confidence_loss = nn.MSELoss()(predicted_confidence, confidence_target_tensor)
|
||||
@ -4559,7 +4589,10 @@ class CleanTradingDashboard:
|
||||
performance_metrics = {
|
||||
'loss': avg_loss,
|
||||
'training_samples': training_samples,
|
||||
'model_parameters': sum(p.numel() for p in network.parameters())
|
||||
'model_parameters': sum(p.numel() for p in network.parameters()),
|
||||
'loss_improvement': 1.0 / (1.0 + avg_loss), # Higher is better
|
||||
'training_iterations': loss_count,
|
||||
'average_confidence': confidence_target if 'confidence_target' in locals() else 0.5
|
||||
}
|
||||
|
||||
metadata = save_checkpoint(
|
||||
@ -4577,7 +4610,9 @@ class CleanTradingDashboard:
|
||||
logger.error(f"Error saving decision fusion checkpoint: {e}")
|
||||
|
||||
if training_samples > 0:
|
||||
logger.info(f"DECISION TRAINING: Processed {training_samples} decision fusion samples")
|
||||
avg_loss_info = f", avg_loss={total_loss/loss_count:.6f}" if loss_count > 0 else ""
|
||||
performance_score = 100 / (1 + (total_loss/loss_count)) if loss_count > 0 else 0.1
|
||||
logger.info(f"DECISION TRAINING: Processed {training_samples} decision fusion samples{avg_loss_info}, perf_score={performance_score:.4f}")
|
||||
except Exception as e:
|
||||
logger.error(f"Error in real decision fusion training: {e}")
|
||||
|
||||
|
Reference in New Issue
Block a user