auto: 일일 백업 2026-06-11 02:00

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hyowons
2026-06-11 02:00:01 +09:00
parent af058cf36d
commit 81e8847a8e
14 changed files with 1064 additions and 342 deletions
+10 -3
View File
@@ -9,7 +9,8 @@ from __future__ import annotations
import json
from datetime import datetime
from . import config, signals
from . import config
from .signals import target_value as _sizing_value # buy()의 signals 파라미터가 모듈명을 가려서 직접 import
def _now_iso() -> str:
@@ -28,6 +29,7 @@ class Portfolio:
self.max_drawdown: float = data.get('max_drawdown', 0.0)
self.created_at: str = data.get('created_at', _now_iso())
self.updated_at: str = data.get('updated_at', self.created_at)
self.last_exit: dict[str, str] = data.get('last_exit', {}) # code → 전량청산 날짜(YYYY-MM-DD), 당일 재진입 금지용
# 영속화 경로 (변이는 별도 경로, 기본은 메인 sim)
self._pf_path = config.PORTFOLIO_PATH
self._trades_path = config.TRADES_PATH
@@ -55,7 +57,7 @@ class Portfolio:
'cash': self.cash, 'initial': self.initial, 'positions': self.positions,
'realized_pnl': self.realized_pnl, 'closed_trades': self.closed_trades,
'wins': self.wins, 'peak_equity': self.peak_equity,
'max_drawdown': self.max_drawdown,
'max_drawdown': self.max_drawdown, 'last_exit': self.last_exit,
'created_at': self.created_at, 'updated_at': self.updated_at,
}, ensure_ascii=False, indent=2))
@@ -83,7 +85,7 @@ class Portfolio:
"""신규 진입(1차 트랜치). 목표비중을 ENTRY_TRANCHES 로 나눈 만큼만 매수. 체결 dict 또는 None."""
if code in self.positions or not self.can_open():
return None
full_target = signals.target_value(self.equity_estimate(), fill_price, stop)
full_target = _sizing_value(self.equity_estimate(), fill_price, stop)
tranche_val = full_target / max(1, config.ENTRY_TRANCHES)
qty = self._qty_for(fill_price, tranche_val)
if qty < 1:
@@ -169,8 +171,13 @@ class Portfolio:
if pnl > 0:
self.wins += 1
del self.positions[code]
self.last_exit[code] = _now_iso()[:10] # 당일 재진입 금지 기준
return rec
def exited_today(self, code: str) -> bool:
"""오늘 전량청산한 종목인지 — 당일 재진입(휩쏘 churn) 방지."""
return self.last_exit.get(code) == _now_iso()[:10]
def apply_position_update(self, code: str, upd: dict):
if code in self.positions:
self.positions[code].update(upd)