feat: instrument analysis

This commit is contained in:
OpenSquared
2026-06-29 00:06:14 +02:00
parent 3bcecdab09
commit 5e65424500
3 changed files with 28 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ regime detection, trend summary, event filtering, and AI narrative.
"""
import json
import os
import re
import logging
import numpy as np
import pandas as pd
@@ -12,6 +13,11 @@ from pathlib import Path
from typing import Dict, Any, List, Optional, Tuple
from datetime import datetime, date
def _base_ticker(t: str) -> str:
"""Normalize Yahoo Finance tickers for comparison: EURUSD=X → EURUSD, BZ=F → BZ, ^GSPC → GSPC."""
return re.sub(r'(=X|=F|=RR|-USD|\^)$', '', t.strip().upper())
logger = logging.getLogger(__name__)
# ── Config loading ─────────────────────────────────────────────────────────────
@@ -586,8 +592,10 @@ def _get_relevant_events(
asset_hit = any(ra in ev_assets for ra in related)
# Always include events that have a causal analysis for this instrument
# Normalize tickers: strip Yahoo Finance suffixes (=X, =F, ^, -USD, =RR) for comparison
analyzed = ev.get("analyzed_instruments") or ""
analysis_hit = inst_upper and inst_upper in [i.strip().upper() for i in analyzed.split(",") if i.strip()]
analyzed_bases = [_base_ticker(s) for s in analyzed.split(",") if s.strip()]
analysis_hit = bool(inst_upper and _base_ticker(inst_upper) in analyzed_bases)
if keyword_hit or asset_hit or analysis_hit:
filtered.append({