fix: 바스켓 계정 자본 중앙 해석 — 주문 리스크 가드 분모 오류 수복#449
Merged
Conversation
6차 점검: 8/1 입금 흐름을 격리 DB에서 실코드 E2E로 실행하다 발견. 주문 리스크 가드(_drawdown_pre_order_check — MDD·일일 손실 한도로 신규 BUY 차단)가 PortfolioManager를 account_key만으로 열어 전역 자본(10M)으로 폴백 → 30만 kr_pocket의 총평가가 10.4M로 오산돼 손실 한도가 사실상 무력화되던 결함. #426이 평가기의 바스켓별 자본은 고쳤지만 이 폴백은 남아 있었다. paper에선 조용하지만 live 전환 시 리스크 가드 구멍이 된다. 수정: PortfolioManager.__init__이 basket_rebalance:<name> 계정 키면 baskets.yaml의 바스켓별 initial_capital을 중앙 해석(지연 임포트로 순환 참조 회피, 해석 실패 시 기존 전역 폴백 유지) — account_key만으로 이 계정을 여는 현재·미래 호출부(주문 가드, live 동기화 등)를 일괄 커버. 명시 인자·비바스켓 키는 기존 동작 그대로(테스트 고정). 검증: 격리 DB 실측 — 가드 경로 PM 자본 300,000·총평가 519,981(이전 10.4M) 정상화. E2E(입금 중화·40만 보류·52만 흡수)도 실코드 PASS. 회귀 4케이스 + 전체 스위트 1660 통과.
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.
무엇
6차 점검 — 8/1 입금 흐름을 격리 DB에서 실코드 E2E로 실행하다 발견한 리스크 가드 결함 수복.
E2E 결과 (먼저 좋은 소식)
격리 DB + 실시세로 전 구간 PASS: 첫 매수(1주) → 10만 입금 시 TWR 불변(-0.04% 유지, 입금≠수익) → 잔고 40만에서 매수 보류(부족분 < 1주, 0주문) → 52만에서 1주 흡수(BUY). 5차의 수치 분석이 실코드로 확인됐습니다.
발견된 결함
E2E 로그에서 포착: 주문 리스크 가드(
_drawdown_pre_order_check— MDD·일일 손실 한도로 신규 BUY 차단)가PortfolioManager를 account_key만으로 열어 전역 자본(10M)으로 폴백 → 30만 kr_pocket의 총평가가 10.4M로 오산되어 손실 한도가 사실상 무력화. #426이 평가기의 바스켓별 자본은 고쳤지만 이 폴백은 남아 있었습니다. paper에선 조용하지만 live 전환 시 리스크 가드 구멍이 됩니다.수정
PortfolioManager.__init__가basket_rebalance:<name>계정 키면 baskets.yaml의 바스켓별initial_capital을 중앙 해석(지연 임포트로 순환 참조 회피, 실패 시 기존 폴백 유지) — account_key만으로 이 계정을 여는 현재·미래 호출부를 일괄 커버. 명시 인자·비바스켓 키는 기존 동작 그대로.검증