feat: 적립 입금 + 시간가중수익률(TWR) — 소액 적립 트랙 선행 구현 - #437
Merged
Conversation
월 10만원 적립이 운영의 중심(docs/POCKET_TRACK_PLAN.md)인데, 기존 수익률 산식(총평가/초기자본)은 입금을 수익으로 오표기한다(30만에 10만 입금=+33%). 핵심 계약: 1) 입금은 수익이 아니다 — 입금 직후 수익률·실현손익 점프 0 2) MDD는 TWR 지수 기준 — 입금이 낙폭을 가짜 회복시키지 않는다 3) 흐름 0건 계정은 기존 산식 그대로 — 기존 트랙 결과 불변(회귀 고정) 구현: - database: cash_flows 테이블 + record/조회/구간합/최신 스냅샷 요약 - portfolio_manager: twr_period_return(순수) + summary TWR 분기(직전 스냅샷 누적수익률에 구간 수익률 연결, 유입 경계는 측정 시각 created_at), 현금엔 입금 포함·손익 제외, deposits_total/principal 노출 - main: 일간 수익률 입금 중화 + 카드 누적 원금, 주간 변화도 입금 중화 - basket_evaluation: 입금 계정 NAV는 스냅샷 TWR, 비용 분모는 시간가중 평균 자본(Modified Dietz — 말기 입금이 게이트를 느슨하게 못 하게) - tools/record_deposit.py: 입금 CLI(양수만, 마지막 스냅샷 이전 소급 거부) - restart_basket_track_record: CashFlow도 아카이브 이전(재시작 후 잔류 방지) 적대적 리뷰 6건 반영 — 특히 HIGH: 스냅샷 upsert가 created_at(측정 시각)을 갱신하지 않아 당일 재실행(재시도 크론)+입금 조합에서 다음 날 유입이 이중 산입돼 수익률이 영구 왜곡되던 문제 → upsert 시 갱신 + 회귀 테스트. 격리 임시 DB 실CLI 스모크 확인. 전체 스위트 1627 통과.
easygap
added a commit
that referenced
this pull request
Jul 6, 2026
feat: 적립 입금 + 시간가중수익률(TWR) — 소액 적립 트랙 선행 구현
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
무엇
소액 적립 트랙(docs/POCKET_TRACK_PLAN.md §4)의 선행 구현 — 외부 입금 지원 + 시간가중수익률(TWR). 월 10만원 적립이 운영의 중심인데, 현 수익률 산식(총평가/초기자본)은 입금을 수익으로 오표기합니다(30만에 10만 입금 = +33%).
핵심 계약
구현
database:cash_flows테이블(+입금/-출금, 발생 시각) + record/조회/구간합/최신 스냅샷 요약 repo 함수.core/portfolio_manager.py: 순수twr_period_return+ summary의 TWR 분기(직전 스냅샷 누적수익률에 구간 수익률 연결, 유입 경계는 측정 시각 created_at), 현금엔 입금 포함·손익에선 제외,deposits_total/principal노출.main.py: 일간 수익률 입금 중화 + 카드에 💳 누적 원금(입금 계정만), 주간 리포트 주간 변화도 입금 중화.core/basket_evaluation.py: 입금 계정의 NAV는 스냅샷 TWR 누적치, 비용 드래그 분모는 시간가중 평균 자본(Modified Dietz).tools/record_deposit.py: 입금 기록 CLI(양수만, 마지막 스냅샷 이전 소급 거부 — TWR 체인 보호).tools/restart_basket_track_record.py: 아카이브 이전 목록에 CashFlow 추가(재시작 후 옛 입금 잔류 방지).적대적 리뷰 반영 (6건 확정 → 전부 수정)
검증
tests/test_cash_flows.py23케이스(계약 3종 + 리뷰 회귀 6종 + CLI/재시작 이전).