From c2cab31e1ea05e92e51b561ce9c4aeb429a2b15d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 12 Mar 2025 10:23:41 +0100 Subject: [PATCH] refactor(qav3): cleanup period objective function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../LightGBMRegressorQuickAdapterV35.py | 27 +++++++++++-------- .../XGBoostRegressorQuickAdapterV35.py | 27 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py index d813d3b..1081505 100644 --- a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py @@ -569,17 +569,6 @@ def period_objective( test_window = trial.suggest_int( "test_period_candles", min_test_window, max_test_window, step=candles_step ) - min_label_period_candles: int = 10 - max_label_period_candles: int = min( - max(fit_live_predictions_candles // 6, min_label_period_candles), test_window - ) - label_period_candles = trial.suggest_int( - "label_period_candles", - min_label_period_candles, - max_label_period_candles, - step=candles_step, - ) - test_window = (test_window // label_period_candles) * label_period_candles X_test = X_test.iloc[-test_window:] y_test = y_test.iloc[-test_window:] test_weights = test_weights[-test_window:] @@ -597,6 +586,22 @@ def period_objective( ) y_pred = model.predict(X_test) + min_label_period_candles: int = 10 + max_label_period_candles: int = max( + fit_live_predictions_candles // 6, min_label_period_candles + ) + label_period_candles = trial.suggest_int( + "label_period_candles", + min_label_period_candles, + max_label_period_candles, + step=candles_step, + ) + label_period_candles_length = ( + len(y_test) // label_period_candles + ) * label_period_candles + y_test = y_test.iloc[-label_period_candles_length:] + test_weights = test_weights[-label_period_candles_length:] + y_pred = y_pred[-label_period_candles_length:] n_windows = len(y_test) // label_period_candles y_test = [ y_test.iloc[i : i + label_period_candles].to_numpy() diff --git a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py index 8feb2c8..e7a46f5 100644 --- a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py @@ -572,17 +572,6 @@ def period_objective( test_window = trial.suggest_int( "test_period_candles", min_test_window, max_test_window, step=candles_step ) - min_label_period_candles: int = 10 - max_label_period_candles: int = min( - max(fit_live_predictions_candles // 6, min_label_period_candles), test_window - ) - label_period_candles = trial.suggest_int( - "label_period_candles", - min_label_period_candles, - max_label_period_candles, - step=candles_step, - ) - test_window = (test_window // label_period_candles) * label_period_candles X_test = X_test.iloc[-test_window:] y_test = y_test.iloc[-test_window:] test_weights = test_weights[-test_window:] @@ -605,6 +594,22 @@ def period_objective( ) y_pred = model.predict(X_test) + min_label_period_candles: int = 10 + max_label_period_candles: int = max( + fit_live_predictions_candles // 6, min_label_period_candles + ) + label_period_candles = trial.suggest_int( + "label_period_candles", + min_label_period_candles, + max_label_period_candles, + step=candles_step, + ) + label_period_candles_length = ( + len(y_test) // label_period_candles + ) * label_period_candles + y_test = y_test.iloc[-label_period_candles_length:] + test_weights = test_weights[-label_period_candles_length:] + y_pred = y_pred[-label_period_candles_length:] n_windows = len(y_test) // label_period_candles y_test = [ y_test.iloc[i : i + label_period_candles].to_numpy() -- 2.43.0