{
  "dashboard_title": "Prediction Accuracy",
  "description": "Predicted signals vs realized price moves, confidence calibration, and model accuracy tracking.",
  "slug": "prediction-accuracy",
  "position_json": {
    "HEADER_ID": {"id": "HEADER_ID", "type": "HEADER", "meta": {"text": "Prediction Accuracy"}},
    "ROW-1": {
      "type": "ROW",
      "children": ["CHART-overall-hit-rate-kpi", "CHART-total-predictions-kpi", "CHART-avg-confidence-kpi", "CHART-avg-move-kpi"]
    },
    "ROW-2": {
      "type": "ROW",
      "children": ["CHART-hit-rate-timeseries", "CHART-outcome-distribution-pie"]
    },
    "ROW-3": {
      "type": "ROW",
      "children": ["CHART-confidence-calibration", "CHART-confidence-vs-move-scatter"]
    },
    "ROW-4": {
      "type": "ROW",
      "children": ["CHART-accuracy-by-symbol", "CHART-accuracy-by-action"]
    },
    "ROW-5": {
      "type": "ROW",
      "children": ["CHART-recent-predictions-table"]
    }
  },
  "metadata": {
    "refresh_frequency": 600,
    "default_filters": "{}",
    "color_scheme": "supersetColors"
  },
  "charts": [
    {
      "slice_name": "Overall Hit Rate",
      "viz_type": "big_number_total",
      "description": "Fraction of predictions with correct directional outcome over the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT ROUND(CAST(COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS DOUBLE) / NULLIF(COUNT(*), 0), 4) AS hit_rate FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY"
    },
    {
      "slice_name": "Total Predictions (30d)",
      "viz_type": "big_number_total",
      "description": "Total evaluated predictions in the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT COUNT(*) AS total_predictions FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY"
    },
    {
      "slice_name": "Avg Predicted Confidence",
      "viz_type": "big_number_total",
      "description": "Average confidence of predictions in the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT ROUND(AVG(predicted_confidence), 3) AS avg_confidence FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY"
    },
    {
      "slice_name": "Avg Realized Move",
      "viz_type": "big_number_total",
      "description": "Average absolute realized price move percentage",
      "datasource_type": "trino",
      "query": "SELECT ROUND(AVG(ABS(actual_move_pct)), 3) AS avg_abs_move FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY"
    },
    {
      "slice_name": "Daily Hit Rate",
      "viz_type": "echarts_timeseries_line",
      "description": "Daily prediction hit rate over the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT dt AS bucket, COUNT(*) AS total, COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS correct, ROUND(CAST(COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS DOUBLE) / NULLIF(COUNT(*), 0), 4) AS hit_rate FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY dt ORDER BY dt"
    },
    {
      "slice_name": "Outcome Distribution",
      "viz_type": "pie",
      "description": "Breakdown of prediction outcomes (correct, incorrect, neutral) over the last 30 days",
      "datasource_type": "trino",
      "query": "SELECT outcome, COUNT(*) AS count FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY outcome ORDER BY count DESC"
    },
    {
      "slice_name": "Confidence Calibration",
      "viz_type": "echarts_timeseries_bar",
      "description": "Hit rate by confidence bucket to assess calibration quality",
      "datasource_type": "trino",
      "query": "SELECT CASE WHEN predicted_confidence >= 0.8 THEN '0.8-1.0 (high)' WHEN predicted_confidence >= 0.6 THEN '0.6-0.8 (medium)' WHEN predicted_confidence >= 0.4 THEN '0.4-0.6 (low)' ELSE '0.0-0.4 (very low)' END AS confidence_bucket, COUNT(*) AS total, COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS correct, ROUND(CAST(COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS DOUBLE) / NULLIF(COUNT(*), 0), 4) AS hit_rate FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY 1 ORDER BY 1",
      "params": {
        "x_axis": "confidence_bucket",
        "metrics": ["hit_rate"]
      }
    },
    {
      "slice_name": "Confidence vs Realized Move",
      "viz_type": "echarts_timeseries_scatter",
      "description": "Scatter plot of predicted confidence vs actual realized move percentage",
      "datasource_type": "trino",
      "query": "SELECT ticker, predicted_confidence, actual_move_pct, predicted_action, outcome, dt FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY ORDER BY dt DESC",
      "params": {
        "x_axis": "predicted_confidence",
        "y_axis": "actual_move_pct",
        "groupby": ["outcome"]
      }
    },
    {
      "slice_name": "Accuracy by Symbol",
      "viz_type": "table",
      "description": "Per-symbol prediction accuracy summary",
      "datasource_type": "trino",
      "query": "SELECT ticker, COUNT(*) AS predictions, COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS correct, COUNT(CASE WHEN outcome = 'incorrect' THEN 1 END) AS incorrect, ROUND(CAST(COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS DOUBLE) / NULLIF(COUNT(*), 0), 4) AS hit_rate, ROUND(AVG(predicted_confidence), 3) AS avg_confidence, ROUND(AVG(actual_move_pct), 3) AS avg_move_pct, ROUND(AVG(ABS(actual_move_pct)), 3) AS avg_abs_move_pct FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY ticker ORDER BY hit_rate DESC"
    },
    {
      "slice_name": "Accuracy by Action Type",
      "viz_type": "echarts_timeseries_bar",
      "description": "Hit rate broken down by predicted action (buy, sell, hold, watch)",
      "datasource_type": "trino",
      "query": "SELECT predicted_action, COUNT(*) AS total, COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS correct, ROUND(CAST(COUNT(CASE WHEN outcome = 'correct' THEN 1 END) AS DOUBLE) / NULLIF(COUNT(*), 0), 4) AS hit_rate, ROUND(AVG(predicted_confidence), 3) AS avg_confidence FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '30' DAY GROUP BY predicted_action ORDER BY predicted_action",
      "params": {
        "x_axis": "predicted_action",
        "metrics": ["hit_rate"]
      }
    },
    {
      "slice_name": "Recent Predictions",
      "viz_type": "table",
      "description": "Most recent evaluated predictions with outcomes",
      "datasource_type": "trino",
      "query": "SELECT ticker, predicted_action, ROUND(predicted_confidence, 3) AS confidence, ROUND(actual_move_pct, 3) AS actual_move_pct, outcome, horizon_days, model_version, predicted_at, evaluated_at FROM lakehouse.stonks.prediction_vs_outcome WHERE dt >= CURRENT_DATE - INTERVAL '14' DAY ORDER BY evaluated_at DESC LIMIT 50"
    }
  ]
}
