feat: add backtest module with DB cache and scenario comparison

Backtest improvements:
- Add backtest.py with Oracle DB-backed OHLCV cache (no repeated API calls)
- Add backtest_trades table to cache simulation results by params hash
  (same params -> instant load, skip re-simulation)
- Add walk-forward scenario comparison (--walkforward-cmp)
- Add trend ceiling filter (--trend-cmp, max gain threshold)
- Add ticker win-rate filter (--ticker-cmp, SQL-based instant analysis)
- Precompute daily_features once per data load (not per scenario)

Live bot fixes:
- monitor: add hard stop-loss from buy price (in addition to trailing)
- strategy: fix re-entry condition to require +1% above last sell price
- price_collector: add 48h backfill on startup for trend calculation
- main: call backfill_prices() at startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
joungmin
2026-02-28 23:28:27 +09:00
parent 4888aa0faa
commit 0b264b304c
5 changed files with 1621 additions and 17 deletions

View File

@@ -19,7 +19,7 @@ logging.basicConfig(
from core.monitor import run_monitor
from core.notify import notify_error, notify_status
from core.price_collector import run_collector
from core.price_collector import backfill_prices, run_collector
from core.trader import get_positions, restore_positions
from daemon.runner import run_scanner
@@ -45,6 +45,10 @@ def main() -> None:
# 재시작 시 기존 잔고 복원 (이중 매수 방지)
restore_positions()
# 과거 가격 백필 (추세 판단용 DB 데이터가 없는 경우 채움)
logger.info("과거 가격 백필 시작 (48시간)...")
backfill_prices(hours=48)
# 트레일링 스탑 감시 스레드 (10초 주기)
monitor_thread = threading.Thread(
target=run_monitor, args=(10,), daemon=True, name="monitor"
@@ -57,7 +61,7 @@ def main() -> None:
)
status_thread.start()
# 10분 주기 가격 수집 스레드 (추세 판단용 DB 저장)
# 가격 수집 스레드 (10분 주기 → Oracle DB price_history 저장, 추세 판단용)
collector_thread = threading.Thread(
target=run_collector, daemon=True, name="collector"
)