smaug/signals/cluster_detector.py
Dominik Roth 727ad7cd6d feat(signals): as-of-date aware cluster detection, open-market-only filter
- cluster_detector: pass as_of_date through to DB query so historical signal
  reprocessing doesn't look into the future
- filter_engine: accept as_of_date; skip non-open-market tx_codes (only P/"");
  reject placeholder tickers (NONE, N/A); propagate as_of_date to cluster detection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 17:48:59 +02:00

16 lines
508 B
Python

from typing import Optional
from db.db import get_recent_buys_for_ticker
import config
def detect_cluster(ticker: str, as_of_date: Optional[str] = None) -> dict:
buys = get_recent_buys_for_ticker(ticker, config.CLUSTER_WINDOW_DAYS, as_of_date=as_of_date)
unique_insiders = {b["insider_name"] for b in buys}
total_value = sum(b["total_value"] or 0 for b in buys)
return {
"cluster_size": len(unique_insiders),
"total_cluster_value": total_value,
"buys": buys,
}