price vector predictions
This commit is contained in:
@ -2201,6 +2201,9 @@ class CleanTradingDashboard:
|
||||
self._add_cnn_predictions_to_chart(fig, symbol, df_main, row)
|
||||
self._add_cob_rl_predictions_to_chart(fig, symbol, df_main, row)
|
||||
self._add_prediction_accuracy_feedback(fig, symbol, df_main, row)
|
||||
|
||||
# 3. Add price vector predictions as directional lines
|
||||
self._add_price_vector_predictions_to_chart(fig, symbol, df_main, row)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error adding model predictions to chart: {e}")
|
||||
@ -2590,6 +2593,142 @@ class CleanTradingDashboard:
|
||||
except Exception as e:
|
||||
logger.debug(f"Error adding prediction accuracy feedback to chart: {e}")
|
||||
|
||||
def _add_price_vector_predictions_to_chart(self, fig: go.Figure, symbol: str, df_main: pd.DataFrame, row: int = 1):
|
||||
"""Add price vector predictions as thin directional lines on the chart"""
|
||||
try:
|
||||
# Get recent predictions with price vectors from orchestrator
|
||||
vector_predictions = self._get_recent_vector_predictions(symbol)
|
||||
|
||||
if not vector_predictions:
|
||||
return
|
||||
|
||||
for pred in vector_predictions[-20:]: # Last 20 vector predictions
|
||||
try:
|
||||
timestamp = pred.get('timestamp')
|
||||
price = pred.get('price', 0)
|
||||
vector = pred.get('price_direction', {})
|
||||
confidence = pred.get('confidence', 0)
|
||||
model_name = pred.get('model_name', 'unknown')
|
||||
|
||||
if not vector or price <= 0:
|
||||
continue
|
||||
|
||||
direction = vector.get('direction', 0.0)
|
||||
vector_confidence = vector.get('confidence', 0.0)
|
||||
|
||||
# Skip weak predictions
|
||||
if abs(direction) < 0.1 or vector_confidence < 0.3:
|
||||
continue
|
||||
|
||||
# Calculate vector endpoint
|
||||
# Scale magnitude based on direction and confidence
|
||||
predicted_magnitude = abs(direction) * vector_confidence * 2.0 # Scale to ~2% max
|
||||
price_change = predicted_magnitude if direction > 0 else -predicted_magnitude
|
||||
end_price = price * (1 + price_change / 100.0)
|
||||
|
||||
# Create time projection (5-minute forward projection)
|
||||
if isinstance(timestamp, str):
|
||||
timestamp = pd.to_datetime(timestamp)
|
||||
end_time = timestamp + timedelta(minutes=5)
|
||||
|
||||
# Color based on direction and confidence
|
||||
if direction > 0:
|
||||
# Upward prediction - green shades
|
||||
color = f'rgba(0, 255, 0, {vector_confidence:.2f})'
|
||||
else:
|
||||
# Downward prediction - red shades
|
||||
color = f'rgba(255, 0, 0, {vector_confidence:.2f})'
|
||||
|
||||
# Draw vector line
|
||||
fig.add_trace(
|
||||
go.Scatter(
|
||||
x=[timestamp, end_time],
|
||||
y=[price, end_price],
|
||||
mode='lines',
|
||||
line=dict(
|
||||
color=color,
|
||||
width=2,
|
||||
dash='dot' if vector_confidence < 0.6 else 'solid'
|
||||
),
|
||||
name=f'{model_name.upper()} Vector',
|
||||
showlegend=False,
|
||||
hovertemplate=f"<b>{model_name.upper()} PRICE VECTOR</b><br>" +
|
||||
"Start: $%{y[0]:.2f}<br>" +
|
||||
"Target: $%{y[1]:.2f}<br>" +
|
||||
f"Direction: {direction:+.3f}<br>" +
|
||||
f"V.Confidence: {vector_confidence:.1%}<br>" +
|
||||
f"Magnitude: {predicted_magnitude:.2f}%<br>" +
|
||||
f"Model Confidence: {confidence:.1%}<extra></extra>"
|
||||
),
|
||||
row=row, col=1
|
||||
)
|
||||
|
||||
# Add small marker at vector start
|
||||
marker_color = 'green' if direction > 0 else 'red'
|
||||
fig.add_trace(
|
||||
go.Scatter(
|
||||
x=[timestamp],
|
||||
y=[price],
|
||||
mode='markers',
|
||||
marker=dict(
|
||||
symbol='circle',
|
||||
size=4,
|
||||
color=marker_color,
|
||||
opacity=vector_confidence
|
||||
),
|
||||
name=f'{model_name} Vector Start',
|
||||
showlegend=False,
|
||||
hoverinfo='skip'
|
||||
),
|
||||
row=row, col=1
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Error drawing vector for prediction: {e}")
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Error adding price vector predictions to chart: {e}")
|
||||
|
||||
def _get_recent_vector_predictions(self, symbol: str) -> List[Dict]:
|
||||
"""Get recent predictions that include price vector data"""
|
||||
try:
|
||||
vector_predictions = []
|
||||
|
||||
# Get from orchestrator's recent predictions
|
||||
if hasattr(self.trading_executor, 'orchestrator') and self.trading_executor.orchestrator:
|
||||
orchestrator = self.trading_executor.orchestrator
|
||||
|
||||
# Check last inference data for each model
|
||||
for model_name, inference_data in getattr(orchestrator, 'last_inference', {}).items():
|
||||
if not inference_data:
|
||||
continue
|
||||
|
||||
prediction = inference_data.get('prediction', {})
|
||||
metadata = inference_data.get('metadata', {})
|
||||
|
||||
# Look for price direction in prediction or metadata
|
||||
price_direction = None
|
||||
if 'price_direction' in prediction:
|
||||
price_direction = prediction['price_direction']
|
||||
elif 'price_direction' in metadata:
|
||||
price_direction = metadata['price_direction']
|
||||
|
||||
if price_direction:
|
||||
vector_predictions.append({
|
||||
'timestamp': inference_data.get('timestamp', datetime.now()),
|
||||
'price': inference_data.get('inference_price', 0),
|
||||
'price_direction': price_direction,
|
||||
'confidence': prediction.get('confidence', 0),
|
||||
'model_name': model_name
|
||||
})
|
||||
|
||||
return vector_predictions
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Error getting recent vector predictions: {e}")
|
||||
return []
|
||||
|
||||
def _get_real_cob_rl_predictions(self, symbol: str) -> List[Dict]:
|
||||
"""Get real COB RL predictions from the model"""
|
||||
try:
|
||||
|
Reference in New Issue
Block a user