feat(stock): compute_and_store + build_holdings_brief

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 22:11:45 +09:00
parent c3a3055060
commit 789785fe3a
2 changed files with 96 additions and 0 deletions

View File

@@ -273,3 +273,25 @@ def test_portfolio_health_empty_and_zero():
h1 = hi.portfolio_health([{"ticker": "X", "quantity": 1, "avg_price": 0,
"current_price": 0, "is_krx": True}], total_cash=0)
assert h1["total_pnl_rate"] == 0.0
# ---- Phase 4 tests ----
def test_compute_and_store_and_brief(monkeypatch):
import os, tempfile
from app import db
monkeypatch.setattr(db, "DB_PATH", os.path.join(tempfile.mkdtemp(), "stock.db"))
db.init_db()
monkeypatch.setattr(hi, "get_holdings", lambda: [
{"ticker": "005930", "name": "삼성전자", "quantity": 10, "avg_price": 1000,
"current_price": 1100, "pnl_rate": 10.0, "is_krx": True}])
ctx = _toy_ctx(("005930",))
monkeypatch.setattr(hi, "_load_ctx", lambda asof: ctx)
monkeypatch.setattr(hi, "_news_sentiment_map", lambda date: {})
monkeypatch.setattr(hi.db, "get_all_broker_cash", lambda: [{"broker": "kis", "cash": 500000}])
res = hi.compute_and_store(asof=ctx.asof, use_llm=False)
assert res["stored"] == 1
brief = hi.build_holdings_brief()
assert brief["holdings"][0]["ticker"] == "005930"
assert "portfolio_health" in brief
assert brief["holdings"][0]["action"] in ("add", "hold", "trim", "sell")