#!/bin/bash
set -euo pipefail
cd /home/hoon/kis_bot
mkdir -p logs
TS=$(date +%Y%m%d_%H%M%S)
STUDY="momentum_wide_20260715_${TS}"
LOG="logs/param_search_optuna_momentum_wide_${TS}.log"
echo "$LOG" > logs/param_search_optuna_momentum_wide_latest.logpath
echo "$STUDY" > logs/param_search_optuna_momentum_wide_latest.study

unset MOMENTUM_TRIGGER_E_CONFIRM || true
export MOMENTUM_BACKTEST_REST_WARMUP=1
export MOMENTUM_BACKTEST_REST_WARMUP_BARS="${MOMENTUM_BACKTEST_REST_WARMUP_BARS:-700}"
export MOMENTUM_BACKTEST_REST_SLEEP_SEC="${MOMENTUM_BACKTEST_REST_SLEEP_SEC:-0.25}"

# wide 축 스크리닝 — apply 없음. fine 재설계·적용은 wide Top 확인 후.
nohup python3 -u kis_trader/backtest/param_search_optuna.py \
  --strategy momentum \
  --mode wide \
  --start 2026-07-15 \
  --end 2026-07-15 \
  --trials 100 \
  --min_trades 1 \
  --min_win_rate 0 \
  --min_pf 0 \
  --sort-by pnl \
  --orderbook-filter off \
  --no-progress \
  --study-name "$STUDY" \
  > "$LOG" 2>&1 &
echo "PID=$!"
echo "STUDY=$STUDY"
echo "LOG=$LOG"
echo "tail -f /home/hoon/kis_bot/$LOG"
