feat(screener): ScreenContext.news_sentiment field + load query

This commit is contained in:
2026-05-13 23:41:01 +09:00
parent 2ff2645240
commit 6c3a84b8ec

View File

@@ -17,6 +17,7 @@ class ScreenContext:
flow: pd.DataFrame # cols: ticker,date,foreign_net,institution_net flow: pd.DataFrame # cols: ticker,date,foreign_net,institution_net
kospi: pd.Series # index=date(str), name="kospi" kospi: pd.Series # index=date(str), name="kospi"
asof: dt.date asof: dt.date
news_sentiment: "pd.DataFrame | None" = None
@classmethod @classmethod
def load(cls, conn: sqlite3.Connection, asof: dt.date, def load(cls, conn: sqlite3.Connection, asof: dt.date,
@@ -38,6 +39,10 @@ class ScreenContext:
"FROM krx_flow WHERE date BETWEEN ? AND ? ORDER BY date", "FROM krx_flow WHERE date BETWEEN ? AND ? ORDER BY date",
conn, params=(cutoff, asof_iso), conn, params=(cutoff, asof_iso),
) )
news_sentiment = pd.read_sql_query(
"SELECT ticker, score_raw, news_count FROM news_sentiment WHERE date = ?",
conn, params=(asof_iso,),
)
# KOSPI 지수: MVP에서는 005930(삼성전자) 종가를 시장 대용으로 사용. # KOSPI 지수: MVP에서는 005930(삼성전자) 종가를 시장 대용으로 사용.
# 후속 슬라이스에서 ^KS11 별도 캐시. # 후속 슬라이스에서 ^KS11 별도 캐시.
@@ -47,7 +52,8 @@ class ScreenContext:
kospi = sub.copy() kospi = sub.copy()
kospi.name = "kospi" kospi.name = "kospi"
return cls(master=master, prices=prices, flow=flow, kospi=kospi, asof=asof) return cls(master=master, prices=prices, flow=flow, kospi=kospi, asof=asof,
news_sentiment=news_sentiment)
def restrict(self, tickers) -> "ScreenContext": def restrict(self, tickers) -> "ScreenContext":
tickers = pd.Index(tickers) tickers = pd.Index(tickers)