Skip to content

Commit 0ebc4b9

Browse files
committed
fix: 일일 리포트를 시장가로 평가 — avg_price 평가로 누적수익이 60일 내내 -0.0%로 표시되던 결함 (자기검토 2라운드 HIGH)
1 parent 85be8b2 commit 0ebc4b9

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,14 @@ def run_rebalance(args):
769769
# 에서는 돌지 않아 운영자가 받는 푸시가 0건이었다 — 사이클마다 바스켓
770770
# NAV 요약 카드를 보낸다. 실패해도 사이클에는 영향 없음(채널은 보조).
771771
try:
772-
summary_data = rebalancer.portfolio_mgr.get_portfolio_summary()
772+
# 시장가 기준으로 평가해야 한다 — current_prices 없이 호출하면 paper
773+
# 포지션이 avg_price로 평가돼 누적수익 −0.0%·MDD 0.0%가 60일 내내
774+
# 표시된다(자기검토 2라운드 HIGH). 스냅샷 단계가 채운 가격 캐시 재사용.
775+
_snap_cache = getattr(rebalancer, "_market_snapshot", None) or {}
776+
_prices = {s: v["price"] for s, v in _snap_cache.items()}
777+
summary_data = rebalancer.portfolio_mgr.get_portfolio_summary(
778+
current_prices=_prices or None,
779+
)
773780
# 일간 수익률: 직전 스냅샷 대비 (summary에는 누적치만 있다)
774781
daily_ret = 0.0
775782
try:

tests/test_rebalance_snapshot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def test_paper_rebalance_sends_daily_discord_report(patched_rebalance, monkeypat
8585

8686
fake_notifier = MagicMock()
8787
monkeypatch.setattr("core.notifier.Notifier", MagicMock(return_value=fake_notifier))
88+
patched_rebalance._market_snapshot = {"005930": {"price": 61000.0}}
8889
patched_rebalance.portfolio_mgr.get_portfolio_summary.return_value = {
8990
"total_value": 9_800_000, "cash": 2_000_000, "total_return": -2.0,
9091
"mdd": 2.0, "position_count": 9,
@@ -94,6 +95,10 @@ def test_paper_rebalance_sends_daily_discord_report(patched_rebalance, monkeypat
9495
payload = fake_notifier.send_daily_report.call_args.args[0]
9596
assert payload["total_value"] == 9_800_000
9697
assert payload["position_count"] == 9
98+
# 시장가 평가 계약: current_prices 없이 부르면 paper 포지션이 avg_price로 평가돼
99+
# 누적수익 -0.0%/MDD 0%가 60일 내내 표시된다(자기검토 2라운드 HIGH) — 가격 전달 고정.
100+
summary_kwargs = patched_rebalance.portfolio_mgr.get_portfolio_summary.call_args.kwargs
101+
assert summary_kwargs.get("current_prices") == {"005930": 61000.0}
97102

98103

99104
def test_dry_run_rebalance_does_not_send_daily_report(patched_rebalance, monkeypatch):

0 commit comments

Comments
 (0)