ls증권 히스토리 구독 넣음
This commit is contained in:
124
scripts/run_optuna_us_fee_apply.sh
Executable file
124
scripts/run_optuna_us_fee_apply.sh
Executable file
@@ -0,0 +1,124 @@
|
||||
#!/bin/bash
|
||||
# 해외 수수료·SEC·환전 반영 후 US 모멘텀 Optuna 재탐색 + apply-best
|
||||
# nohup bash scripts/run_optuna_us_fee_apply.sh >> logs/optuna_us_fee_master_nohup.log 2>&1 &
|
||||
# tail -f "$(cat logs/optuna_us_fee_latest_master.logpath)"
|
||||
|
||||
set -euo pipefail
|
||||
cd /home/hoon/kis_bot
|
||||
mkdir -p logs kis_trader/backtest/results
|
||||
|
||||
START="${START:-2026-07-21}"
|
||||
END="${END:-2026-07-23}"
|
||||
MODE="${MODE:-tpe}"
|
||||
US_TRIALS="${US_TRIALS:-100}"
|
||||
MIN_TRADES="${MIN_TRADES:-1}"
|
||||
MIN_WIN_RATE="${MIN_WIN_RATE:-0}"
|
||||
MIN_PF="${MIN_PF:-0}"
|
||||
US_SYMBOLS="${US_SYMBOLS:-QQQM SPCX SPYM TSLA}"
|
||||
PY="${PY:-.venv/bin/python}"
|
||||
TS0="$(date +%Y%m%d_%H%M%S)"
|
||||
MASTER="logs/optuna_us_fee_${START}_${END}_${TS0}_master.log"
|
||||
REPORT="logs/optuna_us_fee_${START}_${END}_${TS0}_report.txt"
|
||||
|
||||
{
|
||||
echo "======== US fee/FX Optuna FULL+APPLY $(date -Is) ========"
|
||||
echo "START=$START END=$END MODE=$MODE US_TRIALS=$US_TRIALS"
|
||||
echo "US_SYMBOLS=$US_SYMBOLS"
|
||||
echo "apply-best=ON"
|
||||
echo "master=$MASTER"
|
||||
"$PY" - <<'PY'
|
||||
from kis_trader.engine.us_momentum_env_keys import us_momentum_trading_cost_rates
|
||||
from kis_trader.utils.env import invalidate_merged_env_cache
|
||||
invalidate_merged_env_cache()
|
||||
print("cost_rates", us_momentum_trading_cost_rates())
|
||||
PY
|
||||
} | tee -a "$MASTER"
|
||||
echo "$MASTER" > logs/optuna_us_fee_latest_master.logpath
|
||||
echo "$REPORT" > logs/optuna_us_fee_latest_report.path
|
||||
|
||||
run_one() {
|
||||
local symbol="${1:-}"
|
||||
local ts study log tag
|
||||
ts="$(date +%Y%m%d_%H%M%S)"
|
||||
tag="us_momentum"
|
||||
if [[ -n "$symbol" ]]; then
|
||||
tag="us_momentum_${symbol}"
|
||||
fi
|
||||
# 새 study — fee 반영 재탐색 (구 study 재사용 금지)
|
||||
study="${tag}_${MODE}_fee_${START//-/}_${END//-/}_${ts}"
|
||||
log="logs/optuna_${tag}_${MODE}_fee_${ts}.log"
|
||||
|
||||
{
|
||||
echo ""
|
||||
echo "-------- [$tag] START $(date -Is) study=$study trials=$US_TRIALS --------"
|
||||
} | tee -a "$MASTER"
|
||||
echo "$log" > "logs/optuna_${tag}_${MODE}_latest.logpath"
|
||||
echo "$study" > "logs/optuna_${tag}_${MODE}_latest.study"
|
||||
|
||||
set +e
|
||||
local cmd=(
|
||||
"$PY" -u kis_trader/backtest/param_search_optuna.py
|
||||
--strategy us_momentum
|
||||
--mode "$MODE"
|
||||
--start "$START"
|
||||
--end "$END"
|
||||
--trials "$US_TRIALS"
|
||||
--min_trades "$MIN_TRADES"
|
||||
--min_win_rate "$MIN_WIN_RATE"
|
||||
--min_pf "$MIN_PF"
|
||||
--orderbook-filter off
|
||||
--no-progress
|
||||
--study-name "$study"
|
||||
--sort-by score
|
||||
--apply-best
|
||||
)
|
||||
if [[ -n "$symbol" ]]; then
|
||||
cmd+=(--symbol "$symbol")
|
||||
fi
|
||||
"${cmd[@]}" >"$log" 2>&1
|
||||
local rc=$?
|
||||
set -e
|
||||
|
||||
{
|
||||
echo "-------- [$tag] END rc=$rc $(date -Is) --------"
|
||||
echo "LOG=$log"
|
||||
grep -E 'OPTUNA_RESULT_JSON=|Best trial|apply-best|gated|DB 미적용|❌|KeyError|Traceback|fee_rate|fx_fee' "$log" | tail -n 40 || true
|
||||
} | tee -a "$MASTER"
|
||||
|
||||
if [[ "$rc" -ne 0 ]]; then
|
||||
echo "⚠️ [$tag] 실패 rc=$rc — 계속" | tee -a "$MASTER"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
run_one ""
|
||||
for sym in $US_SYMBOLS; do
|
||||
run_one "$sym"
|
||||
done
|
||||
|
||||
{
|
||||
echo ""
|
||||
echo "======== US Optuna ALL DONE $(date -Is) ========"
|
||||
} | tee -a "$MASTER"
|
||||
|
||||
{
|
||||
echo ""
|
||||
echo "======== POST: US web backtest smoke $(date -Is) ========"
|
||||
} | tee -a "$MASTER"
|
||||
|
||||
set +e
|
||||
"$PY" -u scripts/post_optuna_mid_enroll_verify.py \
|
||||
--start "$START" --end "$END" \
|
||||
--report "$REPORT" \
|
||||
--us-only \
|
||||
>>"$MASTER" 2>&1
|
||||
vrc=$?
|
||||
set -e
|
||||
echo "verify_rc=$vrc report=$REPORT" | tee -a "$MASTER"
|
||||
|
||||
{
|
||||
echo ""
|
||||
echo "======== ALL PIPELINE DONE $(date -Is) ========"
|
||||
echo "master=$MASTER"
|
||||
echo "report=$REPORT"
|
||||
} | tee -a "$MASTER"
|
||||
Reference in New Issue
Block a user