Overhaul news engine: fix false signals, add surprise detection + caching
Improvements from a live-verified audit of the news/calendar pipeline: - Currency tagging: keyword matching now uses letter-boundary regexes and drops ambiguous "us "/"eu "/"uk " tokens — "versus" no longer tags headlines as USD (confirmed live false positive polluting the XAU/USD sentiment average). - Fetch caching: calendar events and headlines are cached class-level (10 min TTL, 60s retry after empty/failed fetch, lock-guarded for concurrent scans). Stops per-scan refetching that was tripping the Forex Factory rate limit; TTL stays under the 30-min pre-event buffer so the danger window can't go stale. - Surprise detection: EconomicEvent.surprise is computed from parsed actual vs forecast (handles %, K/M/B/T suffixes, negatives). A surprise print widens the post-release caution window to 45 min; inline releases keep the original 15 min. - Gold-aware sentiment: headlines are scored per currency, with monetary-policy keywords (hawkish/rate hike/tightening vs dovish/ rate cut/easing/stimulus) inverted for XAU — "hawkish Fed" headlines scored +1.0 for gold before, -1.0 now (verified on live feed). - New sentiment sources: Google News gold-focused query and CNBC Economy RSS (verified live; 40 → 74 unique headlines). Added cross-feed title dedup so syndicated stories count once. - events_today now buckets by UTC date (feed timestamps carry US- Eastern offsets); --json output includes news_description. - Removed dead NewsConfig.min_impact and unused HIGH_IMPACT_EVENTS. Tests: 142 passed (7 new covering boundary matching, surprise classification, post-event windows, cache reuse, gold inversion). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -159,13 +159,24 @@ class SignalConfig:
|
||||
class NewsConfig:
|
||||
"""Economic calendar & sentiment."""
|
||||
tracked_currencies: List[str] = field(default_factory=lambda: ["USD", "XAU"])
|
||||
min_impact: str = "medium"
|
||||
pre_event_buffer_minutes: int = 30
|
||||
post_event_buffer_minutes: int = 15
|
||||
# Wider stay-out window after a high-impact release that surprised
|
||||
# vs forecast (inline releases use post_event_buffer_minutes).
|
||||
post_event_surprise_buffer_minutes: int = 45
|
||||
# How long fetched calendar/headline data is reused across scans.
|
||||
# Must stay below pre_event_buffer_minutes so an event can't cross
|
||||
# into the danger window while a stale cache says it's clear.
|
||||
context_cache_ttl_seconds: int = 600
|
||||
|
||||
rss_feeds: List[str] = field(default_factory=lambda: [
|
||||
"https://investinglive.com/feed/",
|
||||
"https://www.fxstreet.com/rss",
|
||||
# Google News query targeted at gold drivers — also carries Kitco,
|
||||
# Reuters etc. whose direct feeds are unavailable.
|
||||
"https://news.google.com/rss/search?q=gold+price+OR+fed+OR+inflation&hl=en-US&gl=US&ceid=US:en",
|
||||
# CNBC "Economy" section
|
||||
"https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=20910258",
|
||||
])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user