- git mv stock-lab/ → stock/ - docker-compose.yml: 서비스 키 + container_name + build.context + frontend.depends_on + agent-office STOCK_LAB_URL → STOCK_URL - agent-office/app: config.py, service_proxy.py, agents/stock.py, tests/ STOCK_LAB_URL → STOCK_URL - nginx/default.conf: proxy_pass http://stock-lab → http://stock (3 lines) - CLAUDE.md / README.md / STATUS.md / scripts/ 문구 갱신 - stock/ 내부 자기 참조 갱신 lab 네이밍 정책 (feedback_lab_naming.md) graduation. API URL / Python import / DB 파일명 변경 없음.
34 lines
1010 B
Python
34 lines
1010 B
Python
"""외국인 N일 누적 순매수 강도 (시총 대비)."""
|
|
|
|
import pandas as pd
|
|
|
|
from .base import ScoreNode, percentile_rank
|
|
|
|
|
|
class ForeignBuy(ScoreNode):
|
|
name = "foreign_buy"
|
|
label = "외국인 누적 순매수"
|
|
default_params = {"window_days": 5}
|
|
param_schema = {
|
|
"type": "object",
|
|
"properties": {
|
|
"window_days": {"type": "integer", "minimum": 1, "maximum": 60, "default": 5}
|
|
},
|
|
}
|
|
|
|
def compute(self, ctx, params: dict) -> pd.Series:
|
|
window = int(params.get("window_days", 5))
|
|
flow = ctx.flow
|
|
if flow.empty:
|
|
return pd.Series(dtype=float)
|
|
|
|
last_dates = (
|
|
flow.sort_values("date").groupby("ticker").tail(window)
|
|
)
|
|
net_sum = last_dates.groupby("ticker")["foreign_net"].sum()
|
|
|
|
market_cap = ctx.master["market_cap"].fillna(0).reindex(net_sum.index)
|
|
raw = (net_sum / market_cap.replace(0, pd.NA)).astype(float)
|
|
|
|
return percentile_rank(raw).fillna(50.0)
|