Commit Graph

225 Commits

Author SHA1 Message Date
c818810667 수정본
Some checks failed
CI/CD Pipeline / test-backend (push) Has been cancelled
CI/CD Pipeline / test-frontend (push) Has been cancelled
CI/CD Pipeline / build-and-push (push) Has been cancelled
2026-03-27 14:47:49 +09:00
844ee8944f fix: ADX 계산 버그 수정 + Crisis 손절 소급 적용
Some checks failed
CI/CD Pipeline / test-backend (push) Has been cancelled
CI/CD Pipeline / test-frontend (push) Has been cancelled
CI/CD Pipeline / build-and-push (push) Has been cancelled
1. mean_reversion_strategy.py: ADX 초기값을 sum→mean으로 변경
   — ADX가 252로 0-100 범위를 초과하던 버그 수정
   — SIDEWAYS 국면 감지가 정상 작동하도록 복원
   — _wilder_smooth() 함수는 변경하지 않음 (ATR/DM은 합산이 정상)

2. swing/exit_service.py: 고정비율 손절에 적응형 모드 손절값 반영
   — Crisis 모드 전환 시 기존 포지션에도 -3% 손절이 소급 적용됨
   — min(config값, adaptive값)으로 타이트한 쪽 선택

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 11:06:31 +09:00
c0ef58ef5e fix: 최종 회의 CRITICAL 1건 + MEDIUM 2건 수정
1. swing/scheduler: mdd_manager.update() 매 사이클 호출 추가
   — 새 스케줄러에서 MDD -10%/-20% 감지가 완전 무력화되어 있었음
2. mdd_manager: place_order() → safe_place_order() 변경
   — 세마포어+분산락 보호로 이중 매도 방지
3. mdd_manager: 매도 후 ActiveTrade close/update 추가
   — 전량 매도 시 enqueue_close_active_trade()
   — 부분 매도 시 remaining_pct 갱신

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 21:10:59 +09:00
e8ab41d164 chore: 미사용 파일/의존성 정리
- HtsHeader.tsx/css 삭제 (레거시, 미사용)
- realtime/examples.py 삭제 (예제 파일, 프로덕션 미사용)
- backtest_results/ 삭제 + .gitignore 추가
- .env.bak 삭제
- requirements.txt: celery 제거 (미사용), httpx 중복 제거
- package.json: recharts 제거 (미사용)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 20:29:54 +09:00
f92479f3b0 fix: 전체 회의 CRITICAL 6건 수정 — 손절/리스크/성과/인프라
1. trade_executor: 손절값 -6.0 하드코딩 → -settings.STOP_LOSS_PERCENT (7%)
2. mdd_manager: MDD 강제매도 시 loss_tracker 호출 추가
3. risk_validator, day_trading: 가격필터 < → <= (5,000원 정확히 차단)
4. daytrading/entry_service: 글로벌 자본 사용률(95%) 가드 추가
5. trade_analyzer: 수익률 0%를 손실에서 제외 (< 0으로 변경)
6. db_worker: 종료 시 큐 drain + DLQ 백업으로 데이터 유실 방지

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 20:24:59 +09:00
de7921d270 fix: CRITICAL/HIGH 버그 30건 수정 + 전체 코드 주석 추가 + 중복 정리
## CRITICAL 수정 (20건)
- day_trading: global 선언 누락, loss_tracker 연동, ban 체크 추가
- trade_executor: BUY 체결가 order_price로 수정, remaining_pct 누적 계산
- risk_validator: get_current_price dict 파싱, MAX_POSITION_SIZE 동기화, DB 세션 누수
- risk_management/recommendations: date.today() → KST 변환
- mdd_manager: Lock 밖 executed_key 참조 수정
- correlation_filter: output → output2 키 수정
- portfolio: 해외 종목 USD/KRW 환율 적용 분리
- Sharpe Ratio 거래빈도 기반 연간화
- telegram_notifier: send_message() 공개 래퍼 추가
- position_manager: 앱 재시작 시 DB 포지션 복원
- swing exit_service: remaining_pct 조건 범위 수정
- run_backtest: original_qty 기반 remaining_pct 계산
- us_market_schedule: 2027년 미국 공휴일 추가
- Login.tsx: res.ok 검증 추가
- mean_reversion_strategy: RSI 로그 하드코딩 수정

## HIGH 수정 (10건)
- db_worker: DLQ 파일 백업 메커니즘 추가
- korea_investment_api: 만료 토큰 임의 연장 제거
- market_data: chart_cache 최대 100개 + TTL 만료
- main.py: rate_limit_store 1시간 미접근 IP 정리
- recommendations: fire-and-forget try/except 추가
- swing/scheduler: DB 세션 3개 분리
- Dashboard: wsMessages 전체 순회
- Layout: /health 엔드포인트 + 30초 폴링
- ml_ensemble: POST /train require_api_key 추가
- day_trading: record_trade_result_safe() 전환

## 코드 정리
- 프론트엔드: isUsStock, formatTime 공통 유틸 추출
- 백엔드: dead code 제거, 중복 import 통합
- MCP: JSON 파싱 헬퍼 추출 (~60줄 감소)
- 전체 ~100개 파일 한국어 주석 추가
- 테스트 13건 코드 기준 수정 (468 passed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 16:05:41 +09:00
739a8a2e5d 클로드 맥스로 작업중 2026-03-10 20:13:06 +09:00
deb7e7dca8 fix: 시장 레짐 감지 KIS API 전환 + KOSPI/KOSDAQ 균형 배분
- detect_and_log_market_regime(): DB 조회 → KIS API 직접 호출 (KODEX200 069500)
  - 1차 KIS API (320일), 2차 DB 폴백
  - 이전: DB에 KODEX200 데이터 없으면 UNKNOWN → 레짐 필터 미작동
- naver_finance: limit + kospi_ratio 파라미터 추가
  - 기본 KOSPI 60% + KOSDAQ 40% 균형 배분
  - 이전: KOSPI만 500개 채워지고 KOSDAQ 0개 되는 문제 해결
- batch_daily_analysis: 네이버 파이낸스 직접 호출로 변경

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:33:32 +09:00
f6480407f2 test: 상관관계 필터 유닛 테스트 추가
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:26:41 +09:00
ab591f7fd6 feat: MCP 서버 리스크 검증 파이프라인 및 청산 상태머신 개선
- risk_validator.py: 가격/포지션/MDD/레버리지 5단계 검증
- auto_trade_claude.py: 주문 전 리스크 검증 파이프라인 통합
- trade_monitor.py: ATR 기반 익절/트레일링 스탑, API 기반 상태 전환
  (active → pending_sell → closed), 2R 수익 시 50% 분할 매도

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:26:37 +09:00
dc9bc114da refactor: 프론트엔드 TypeScript 타입 안전성 및 커스텀 훅 분리
- types/trading.ts: 중앙 타입 정의 (CandleData, Position, Trade 등)
- useMarketData.ts: 실시간 시세 처리 + 500ms 쓰로틀링
- usePortfolioData.ts: React Query 기반 포트폴리오 데이터 훅
- useTradeActions.ts: 매매 실행 액션 훅
- useWebSocket.ts: pong timeout 10초 감지 (좀비 연결 방지)
- TradingChart.tsx: @ts-nocheck 제거, CandleData 타입 적용
- PortfolioPanel/RecommendationPanel: any → 구체적 타입 교체
- Dashboard.tsx: 상태 관리 로직을 커스텀 훅으로 이전

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:26:27 +09:00
a477072bdc feat: 리스크 관리 강화 — 포트폴리오 락, MDD 단기전략 비활성화, 상관관계 필터
- portfolio.py: summary_lock으로 동시성 보호, apply_buy/apply_sell async화
- mdd_manager.py: MDD -10% 시 단기전략 비활성화 (is_short_term_strategy_paused)
- loss_tracker.py: DB 직접 접근 → db_worker 큐 기반 전환
- db_worker.py: upsert_stock_ban 태스크 추가
- correlation_filter.py: 섹터 집중도 + 피어슨 상관관계 검증 (CLAUDE.md 5.4)
- trade_executor.py: 상관관계 필터 통합, await 적용
- mean_reversion_strategy.py: config 값 타입 안전성 (float 변환)
- main.py/day_trading.py: MDD 체크 후 자동매매/데이트레이딩 차단

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:26:13 +09:00
783e932145 Merge pull request #7 from YoungWooSeo/claude/fix-trading-bugs
fix: 자동매매 미작동 근본 원인 4개 수정
2026-03-10 13:25:26 +09:00
3eb38690fe fix: 자동매매 미작동 근본 원인 4개 수정
## 버그 수정 요약

### 1. 거래량 필터 오작동 (market_analyzer.py)
- acml_vol(당일 누적량, 장초 2~10만주)을 100만주 기준으로 필터
  → 전 종목이 필터에 걸려 추천 종목 0개
- 수정: 20일 평균 거래량(avg_vol_20) 기준 10만주 미만 필터로 교체

### 2. min_volume_ratio 기본값 1.0 미설정 (recommendations.py)
- get_rule_based_recommendations_realtime()에서 min_volume_ratio 누락
  → 기본값 1.0 적용, 장중 acml_vol/avg_vol_20≈0.1 → 전 종목 None 반환
- 수정: min_volume_ratio=0 명시 설정

### 3. KRX 호가단위 오류 (korea_investment_api.py)
- 계산된 주문가격이 호가단위(50/100/500/1000원 등) 불일치
  → 모의투자 "호가단위 오류"로 모든 주문 실패
- 수정: _round_to_krx_tick() 헬퍼 추가, 주문 전 올림 처리

### 4. MCP 서버 AI_PROVIDER 미전달 (docker-compose.dev.yml, mcp-server/config.py)
- mcp-server 서비스에 AI_PROVIDER 환경변수 누락 → 항상 Gemini 사용
- Gemini 무료 쿼터 소진 → /analyze 500 에러 → fail-open
- 수정: AI_PROVIDER=${AI_PROVIDER:-claude} 추가
- 수정: load_dotenv(override=True)로 빈 env var 덮어쓰기 허용

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 13:24:11 +09:00
096e087a9a 코드 변경 2026-03-10 09:49:03 +09:00
a15ecaa314 Merge pull request #6 from YoungWooSeo/claude/naughty-carson
feat: 매매일지 자동 생성 + 전략 자동 최적화 시스템 추가
2026-03-10 09:45:03 +09:00
3a08cd8609 chore: update local settings permissions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 09:38:04 +09:00
2baf06a5fd feat: 매매일지 자동 생성 + 전략 자동 최적화 시스템 추가
- trade_analyzer.py: 거래 성과 분석(승률/손익비/전략별 패턴), 템플릿 기반 일지 자동 생성
- strategy_optimizer.py: 그리드 서치 기반 파라미터 최적화, Sharpe 10% 개선 시 자동 적용
- analysis.py: /performance /insights /generate-journals /optimize-strategy /optimization-history 엔드포인트
- journals.py: POST /generate/{trade_id}, GET /stats 엔드포인트 추가
- models.py: StrategyOptimizationLog 테이블 추가
- main.py: post_market_analyzer_scheduler (16:00 KST 자동 실행)
- frontend: Analysis 페이지 추가 (성과 요약/인사이트/일지 생성/최적화 이력)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 09:28:10 +09:00
f42e94fe6c refactor: 전략 설정 화면 UI 간소화 및 개선
- 프리셋 카드 UI 개선 (3종 → 명확한 비교 표시)
- 필수 설정 6개만 상단 배치
- 중복 파라미터 통합 (RSI 2개 → 1개, 손절 3개 → 1개)
- 그룹별 접기/펼치기 기본값 변경
- 툴팁 및 가이드 추가
2026-03-07 13:35:13 +09:00
7c9b596098 백테스트 수정중 2026-03-07 13:16:01 +09:00
ea355eb60c fix: Update universe presets usage for new API structure 2026-03-06 22:33:19 +09:00
5f84897aa6 fix: Remove Stock model dependency, use StockDailyPrice only 2026-03-06 22:22:33 +09:00
83cf8330b5 fix: Fix group section accordion not working 2026-03-06 22:17:24 +09:00
4473bca7ca fix: Remove unused BacktestResult type 2026-03-06 22:11:20 +09:00
19711705b3 feat: Add bulk universe backtest UI tab 2026-03-06 21:57:15 +09:00
87b4205fb6 feat: Add bulk backtest endpoints for entire stock universe 2026-03-06 21:55:45 +09:00
da4732f1e9 feat: Add stock universe loader for bulk backtest 2026-03-06 21:53:59 +09:00
0c4c888b38 feat: Add Backtest to navigation 2026-03-06 21:29:07 +09:00
3c14be1d97 feat: Add Backtest route to App 2026-03-06 21:28:40 +09:00
38ba5bfbb0 feat: Add backtest UI with ML training data generation and strategy testing 2026-03-06 21:28:16 +09:00
7a31651cc5 feat: Register backtest router in API 2026-03-06 21:27:13 +09:00
d54785f79d feat: Add backtest API endpoints for ML training and strategy testing 2026-03-06 21:26:56 +09:00
943708e68e feat: Add comprehensive backtest engine with ML training data generation 2026-03-06 21:25:49 +09:00
ab6fe810bd feat: Add preset selector and improved UI with collapsible groups 2026-03-06 20:49:05 +09:00
674cb1ef28 feat: Add strategy presets for quick configuration 2026-03-06 20:47:19 +09:00
12460b7c9e 매매전략 수정중 2026-03-06 20:46:08 +09:00
2b9a90a03f 소스리뷰 버전 적용 2026-03-06 19:10:39 +09:00
ab75dc66f8 코드리뷰 수정 2026-03-06 15:22:40 +09:00
da5cef1925 MCP 수정중 2026-03-06 14:40:31 +09:00
ac98bb856f 배치 수정 2026-03-06 14:12:54 +09:00
6d39069d3f merge: phase3 realtime module refactor into main
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 11:05:39 +09:00
eef9620aa6 merge: phase2 strategy module refactor into main
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 11:05:37 +09:00
d341e7e3cc merge: phase1 trading module refactor into main
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 11:05:35 +09:00
48aa5440ec refactor(phase3): Add realtime module examples and README 2026-03-06 11:00:03 +09:00
b1eab5305a refactor(phase3): Add KIS WebSocket client implementation 2026-03-06 10:58:28 +09:00
7355df6ebf refactor(phase3): Create realtime module core structure 2026-03-06 10:57:40 +09:00
a322745cf3 refactor(phase2): Add Scanner module and strategy README 2026-03-06 10:55:19 +09:00
8920699eee refactor(phase2): Add DayTradingStrategy example and indicators module 2026-03-06 10:53:48 +09:00
025ecb5f4f refactor(phase2): Add StrategyManager for strategy orchestration 2026-03-06 10:52:40 +09:00
70dd32a783 refactor(phase2): Create strategy module core structure 2026-03-06 10:51:58 +09:00