From 072910df3934394a2cd7bb28bf7a0c09b78ee007 Mon Sep 17 00:00:00 2001 From: 21in7 Date: Sat, 7 Mar 2026 00:19:27 +0900 Subject: [PATCH] fix: WalkForward ignores use_ml=False flag, always injecting trained models WF backtester always passed trained models to Backtester.run(ml_models=...), overriding ml_filters even when use_ml=False. This caused 0 trades in --no-ml mode because underfitted models (trained on ~27 samples) blocked all entries with proba < 0.55 threshold. - Skip model training when use_ml=False (saves computation) - Only inject ml_models when use_ml=True Co-Authored-By: Claude Opus 4.6 --- src/backtester.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/backtester.py b/src/backtester.py index a2798c2..4efe4f7 100644 --- a/src/backtester.py +++ b/src/backtester.py @@ -244,8 +244,8 @@ class Backtester: ) logger.info(f"[{sym}] 데이터 로드: {len(df):,}캔들 ({df.index[0]} ~ {df.index[-1]})") - # walk-forward 모델 주입 - if ml_models is not None: + # walk-forward 모델 주입 (use_ml=True일 때만) + if ml_models is not None and self.cfg.use_ml: self.ml_filters = {} for sym in self.cfg.symbols: if sym in ml_models and ml_models[sym] is not None: @@ -620,13 +620,14 @@ class WalkForwardBacktester: f"학습 {train_start.date()}~{train_end.date()}, " f"검증 {test_start.date()}~{test_end.date()}") - # 심볼별 모델 학습 + # 심볼별 모델 학습 (use_ml=True일 때만) models = {} - for sym in self.cfg.symbols: - model = self._train_model( - all_raw[sym], train_start, train_end, sym - ) - models[sym] = model + if self.cfg.use_ml: + for sym in self.cfg.symbols: + model = self._train_model( + all_raw[sym], train_start, train_end, sym + ) + models[sym] = model # 검증 구간 백테스트 test_cfg = BacktestConfig(