fix: 손절가 하한 클램프 — 비현실적 손절폭으로 손절이 무력화되는 문제 차단 - #394
Merged
Conversation
ATR이 매우 큰 저가·고변동 종목에서 `entry - atr*배수*국면배수`가 0 이하가 되면 손절가가 음수로 저장되고, 청산 조건 `current_price <= stop_loss_price`가 양수 가격에 대해 영원히 거짓이 되어 손절이 조용히 비활성화된다(무방비 포지션). 고정 손절도 `fixed_rate*국면배수 >= 1`이면 stop >= entry가 되어 즉시 청산된다. calculate_stop_loss에서 손절가가 (0, entry) 범위를 벗어나는 비정상 케이스만 최대 손실폭(stop_loss.max_loss_pct, 기본 0.5) 기준으로 폴백하고 warning을 남긴다. 정상 범위 손절가는 그대로 유지한다. 유동성 필터(20일 평균 거래대금 하한)로 이런 종목은 드물지만, 코드상 방어가 없어 설정·종목에 따라 잠재 손실 위험이 있었다. 회귀 테스트 추가.
easygap
added a commit
that referenced
this pull request
Jul 6, 2026
fix: 손절가 하한 클램프 — 비현실적 손절폭으로 손절이 무력화되는 문제 차단
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.
문제 (LOW, 잠재 무방비 포지션)
calculate_stop_loss에서 손절가가 비정상 값이 되어 손절이 조용히 비활성화될 수 있다.atr*배수 >= entry면 손절가가 0 이하가 되고, 청산 조건current_price <= stop_loss_price가 양수 가격에 대해 영원히 거짓이 되어 손절이 발동하지 않는다(하방 무방비).fixed_rate*국면배수 >= 1이면stop >= entry가 되어 매수 직후 즉시 청산된다.유동성 필터(20일 평균 거래대금 하한)로 이런 종목은 드물지만, 코드상 방어가 전혀 없었다.
수정
손절가가
(0, entry)범위를 벗어나는 비정상 케이스만 최대 손실폭(stop_loss.max_loss_pct, 기본 0.5) 기준으로 폴백하고 warning을 남긴다. 정상 범위 손절가는 그대로 유지한다(동작 변화 없음).테스트
tests/test_risk_stop_loss_floor.py: ATR 음수 손절·고정 100%↑ 손절 폴백, 정상 손절가 불변 검증.