refactor(ml): add MLFilter.from_model(), fix validator initial_balance
- MLFilter.from_model() classmethod eliminates brittle __new__() private-attribute manipulation in backtester walk-forward model injection - backtest_validator._check_invariants() now accepts cfg and uses cfg.initial_balance instead of a hardcoded 1000.0 for the negative-balance invariant check - backtester.py walk-forward injection block simplified to use the new factory method Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -100,3 +100,16 @@ def test_mlx_no_double_normalization():
|
||||
|
||||
assert np.allclose(model._mean, 0.0), "normalize=False시 mean은 0이어야 한다"
|
||||
assert np.allclose(model._std, 1.0), "normalize=False시 std는 1이어야 한다"
|
||||
|
||||
|
||||
def test_ml_filter_from_model():
|
||||
"""MLFilter.from_model()로 LightGBM 모델을 주입할 수 있어야 한다."""
|
||||
from src.ml_filter import MLFilter
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
mock_model = MagicMock()
|
||||
mock_model.predict_proba.return_value = [[0.3, 0.7]]
|
||||
|
||||
mf = MLFilter.from_model(mock_model, threshold=0.55)
|
||||
assert mf.is_model_loaded()
|
||||
assert mf.active_backend == "LightGBM"
|
||||
|
||||
Reference in New Issue
Block a user