[2026-05-28] 외부 데이터 학습 파이프라인 복구

This commit is contained in:
2026-05-28 20:13:27 +09:00
parent 57e945ef28
commit e1a32ce177
6 changed files with 152 additions and 14 deletions
+18 -5
View File
@@ -31,16 +31,29 @@ def _num(value, default=0.0):
return default
def _load_daily_amounts() -> dict[tuple[str, str], dict]:
result = {}
def _load_daily_amounts() -> dict[str, list[dict]]:
by_ticker = defaultdict(dict)
for file in DAILY_ROOT.glob("*/stocks.csv"):
rows = _read_csv(file)
for row in rows:
date = str(row.get("date") or file.parent.name)
ticker = str(row.get("ticker") or row.get("티커") or "")
if ticker:
result[(date, ticker)] = row
return result
row["date"] = date
by_ticker[ticker][date] = row
return {
ticker: [rows[date] for date in sorted(rows)]
for ticker, rows in by_ticker.items()
}
def _previous_daily_row(daily: dict[str, list[dict]], date: str, ticker: str) -> dict:
previous = {}
for row in daily.get(ticker, []):
if str(row.get("date", "")) >= date:
break
previous = row
return previous
def _future_metrics(rows: list[dict], idx: int, entry_price: float):
@@ -84,7 +97,7 @@ def _rows_for_file(path: Path, daily: dict, k: float, breakout_only: bool):
for date in sorted(by_date):
day_rows = by_date[date]
ticker = day_rows[0]["ticker"]
daily_row = daily.get((date, ticker), {})
daily_row = _previous_daily_row(daily, date, ticker)
prev_high = _num(daily_row.get("high"))
prev_low = _num(daily_row.get("low"))
prev_amount = _num(daily_row.get("amount"))