feat: instrument analysis

This commit is contained in:
OpenSquared
2026-06-30 16:15:39 +02:00
parent 69ca36bd7e
commit 9904c066b2
2 changed files with 15 additions and 9 deletions

View File

@@ -42,8 +42,9 @@ interface SnapshotEvent {
category: string; sub_type?: string; description: string; impact_score: number
expected_value?: string | null; actual_value?: string | null
surprise_pct?: number | null; unit?: string | null; absorption_pct?: number | null
prediction_json?: string | null // JSON: {node_id: pips} from causal_event_analyses
actual_json?: string | null // JSON: {instrument: pips} from causal_event_analyses
prediction_json?: string | null // JSON: {node_id: pips} from causal_event_analyses
actual_json?: string | null // JSON: {instrument: pips} from causal_event_analyses
activation_score?: number | null // stored directional accuracy from causal_event_analyses
}
interface RegimeSignals {
@@ -704,6 +705,9 @@ function templateAbsorptionDays(tmpl: CausalTemplate): number {
/** Score 0-100 measuring how well the graph predicted actual pips for an instrument. */
function comprehensionScore(ev: SnapshotEvent, tmpl: CausalTemplate, instrument: string): number | null {
// Prefer the stored activation_score from causal_event_analyses (consistent with MarketEvents panel)
if (ev.activation_score != null) return Math.round(ev.activation_score * 100)
if (!ev.prediction_json || !ev.actual_json) return null
try {
const preds: Record<string, number> = JSON.parse(ev.prediction_json)
@@ -711,7 +715,6 @@ function comprehensionScore(ev: SnapshotEvent, tmpl: CausalTemplate, instrument:
const actual = actuals[instrument] ?? actuals[instrument.toUpperCase()] ?? actuals[instrument.toLowerCase()]
if (actual == null) return null
// Find the output node for this instrument (built-in templates use "output", auto-generated use "market_asset")
const outputNode = tmpl.graph_json.nodes.find(n =>
(n.type === 'market_asset' || n.type === 'output') && n.instrument?.toUpperCase() === instrument.toUpperCase()
)