- 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>
16 lines
508 B
Python
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,
|
|
}
|