feat(screener): AiNewsSentiment ScoreNode (percentile_rank + min_news_count)
This commit is contained in:
36
stock-lab/app/screener/nodes/ai_news.py
Normal file
36
stock-lab/app/screener/nodes/ai_news.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""AI 뉴스 호재/악재 점수 노드.
|
||||
|
||||
ScreenContext.news_sentiment (DataFrame: ticker, score_raw, news_count) 를
|
||||
min_news_count 로 필터한 뒤 percentile_rank 로 0~100 변환.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from .base import ScoreNode, percentile_rank
|
||||
|
||||
|
||||
class AiNewsSentiment(ScoreNode):
|
||||
name = "ai_news"
|
||||
label = "AI 뉴스 호재/악재"
|
||||
default_params = {"min_news_count": 1}
|
||||
param_schema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"min_news_count": {
|
||||
"type": "integer", "minimum": 0, "default": 1,
|
||||
"description": "최소 분석 뉴스 수. 미만이면 점수 미산출.",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def compute(self, ctx, params: dict) -> pd.Series:
|
||||
df = getattr(ctx, "news_sentiment", None)
|
||||
if df is None or df.empty:
|
||||
return pd.Series(dtype=float)
|
||||
min_news = int(params.get("min_news_count", 1))
|
||||
df = df[df["news_count"] >= min_news]
|
||||
if df.empty:
|
||||
return pd.Series(dtype=float)
|
||||
return percentile_rank(df.set_index("ticker")["score_raw"])
|
||||
Reference in New Issue
Block a user