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

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hyowons
2026-06-10 02:00:02 +09:00
parent 0ba61d4d7c
commit 9cc7043490
13 changed files with 695 additions and 119 deletions
+18 -4
View File
@@ -14,9 +14,22 @@ from __future__ import annotations
import math
import sqlite3
import sys
from datetime import datetime
from . import config, signals
def _cal_days(entry_date: str | None, cur_date: str) -> int | None:
"""'YYYYMMDD' 사이 달력 일수 — 시간손절용. 파싱 실패 시 None."""
if not entry_date:
return None
try:
d0 = datetime.strptime(entry_date, '%Y%m%d')
d1 = datetime.strptime(cur_date, '%Y%m%d')
return max(0, (d1 - d0).days)
except Exception:
return None
sys.path.insert(0, str(config.SCRIPTS))
import daily_candles_cache as dcc # noqa: E402
@@ -111,7 +124,8 @@ def run(overrides: dict | None, codes: list[str], date_from: str = '', date_to:
dates_seen = [c['date'] for c in h[:i + 1]]
flow = _flow_net_upto(flows.get(code), dates_seen)
pos = positions[code]
dec = signals.evaluate_holding(pos, ind, flow, None)
dec = signals.evaluate_holding(pos, ind, flow, None,
held_days=_cal_days(pos.get('entry_date'), day))
pos.update(dec['position_update'])
act = dec['action']
if act in ('sell', 'scale_out'):
@@ -170,18 +184,18 @@ def run(overrides: dict | None, codes: list[str], date_from: str = '', date_to:
dec = signals.evaluate_candidate(code, code, [], ind, flow, None, True)
if dec['action'] == 'buy':
fill = dec['buy_price']
stop, target = signals.compute_stop_target(fill, ind['atr'], ind['recent_low'])
eq = equity(day_prices)
tranche_val = (eq / config.MAX_POSITIONS) / max(1, config.ENTRY_TRANCHES)
tranche_val = signals.target_value(eq, fill, stop) / max(1, config.ENTRY_TRANCHES)
qty = _qty_for(fill, tranche_val)
cost = qty * fill * (1 + comm)
if qty < 1 or cost > cash:
continue
stop, target = signals.compute_stop_target(fill, ind['atr'], ind['recent_low'])
cash -= cost
positions[code] = {'code': code, 'name': code, 'qty': qty, 'entry_price': fill,
'stop': stop, 'target': target, 'peak': fill, 'trailing_on': False,
'scaled_out': False, 'tranches': 1, 'tranche_value': tranche_val,
'last_add_price': fill}
'last_add_price': fill, 'entry_date': day}
eq = equity(day_prices)
if eq > peak_eq: