- 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 파일명 변경 없음.
35 lines
950 B
Python
35 lines
950 B
Python
"""20일 모멘텀."""
|
|
|
|
import pandas as pd
|
|
|
|
from .base import ScoreNode, percentile_rank
|
|
|
|
|
|
class Momentum20(ScoreNode):
|
|
name = "momentum"
|
|
label = "20일 모멘텀"
|
|
default_params = {"window_days": 20}
|
|
param_schema = {
|
|
"type": "object",
|
|
"properties": {
|
|
"window_days": {"type": "integer", "minimum": 5, "maximum": 120, "default": 20}
|
|
},
|
|
}
|
|
|
|
def compute(self, ctx, params: dict) -> pd.Series:
|
|
window = int(params.get("window_days", 20))
|
|
prices = ctx.prices
|
|
if prices.empty:
|
|
return pd.Series(dtype=float)
|
|
|
|
ordered = prices.sort_values("date")
|
|
last = ordered.groupby("ticker").tail(window + 1)
|
|
|
|
def _ret(s):
|
|
if len(s) < window + 1:
|
|
return float("nan")
|
|
return s.iloc[-1] / s.iloc[0] - 1
|
|
|
|
raw = last.groupby("ticker")["close"].apply(_ret)
|
|
return percentile_rank(raw).fillna(50.0)
|