From: Jérôme Benoit Date: Tue, 11 Feb 2025 16:35:06 +0000 (+0100) Subject: refactor(qav3): typing X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e0aaead4ed2243083cfacf5b3f8c259a02707fd0;p=freqai-strategies.git refactor(qav3): typing Signed-off-by: Jérôme Benoit --- diff --git a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py index 8889ebb..e299b4b 100644 --- a/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py @@ -242,7 +242,7 @@ class LightGBMRegressorQuickAdapterV35(BaseRegressionModel): def min_max_pred( pred_df: pd.DataFrame, fit_live_predictions_candles: int, label_period_candles: int -): +) -> tuple[float, float]: beta = 10.0 extrema = pred_df.tail(label_period_candles)["&s-extrema"] min_pred = smooth_min(extrema, beta=beta) @@ -253,7 +253,7 @@ def min_max_pred( def __min_max_pred( pred_df: pd.DataFrame, fit_live_predictions_candles: int, label_period_candles: int -): +) -> tuple[float, float]: pred_df_sorted = ( pred_df.select_dtypes(exclude=["object"]) .copy() @@ -280,7 +280,7 @@ def objective( fit_live_predictions_candles, candles_step, params, -): +) -> float: min_train_window: int = 600 max_train_window: int = ( len(X) if len(X) > min_train_window else (min_train_window + len(X)) @@ -333,7 +333,9 @@ def objective( return error -def hp_objective(trial, X, y, train_weights, X_test, y_test, test_weights, params): +def hp_objective( + trial, X, y, train_weights, X_test, y_test, test_weights, params +) -> float: study_params = { "n_estimators": trial.suggest_int("n_estimators", 100, 800), "num_leaves": trial.suggest_int("num_leaves", 2, 256), @@ -369,9 +371,9 @@ def sanitize_path(path: str) -> str: return allowed.sub("_", path) -def smooth_max(series, beta=1.0): +def smooth_max(series: pd.Series, beta=1.0) -> float: return np.log(np.sum(np.exp(beta * series))) / beta -def smooth_min(series, beta=1.0): +def smooth_min(series: pd.Series, beta=1.0) -> float: return -np.log(np.sum(np.exp(-beta * series))) / beta diff --git a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py index 0ba2305..b5de250 100644 --- a/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py +++ b/quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py @@ -245,7 +245,7 @@ class XGBoostRegressorQuickAdapterV35(BaseRegressionModel): def min_max_pred( pred_df: pd.DataFrame, fit_live_predictions_candles: int, label_period_candles: int -): +) -> tuple[float, float]: beta = 10.0 extrema = pred_df.tail(label_period_candles)["&s-extrema"] min_pred = smooth_min(extrema, beta=beta) @@ -256,7 +256,7 @@ def min_max_pred( def __min_max_pred( pred_df: pd.DataFrame, fit_live_predictions_candles: int, label_period_candles: int -): +) -> tuple[float, float]: pred_df_sorted = ( pred_df.select_dtypes(exclude=["object"]) .copy() @@ -283,7 +283,7 @@ def objective( fit_live_predictions_candles, candles_step, params, -): +) -> float: min_train_window: int = 600 max_train_window: int = ( len(X) if len(X) > min_train_window else (min_train_window + len(X)) @@ -341,7 +341,9 @@ def objective( return error -def hp_objective(trial, X, y, train_weights, X_test, y_test, test_weights, params): +def hp_objective( + trial, X, y, train_weights, X_test, y_test, test_weights, params +) -> float: study_params = { "n_estimators": trial.suggest_int("n_estimators", 100, 800), "learning_rate": trial.suggest_float("learning_rate", 1e-3, 0.3, log=True), @@ -382,9 +384,9 @@ def sanitize_path(path: str) -> str: return allowed.sub("_", path) -def smooth_max(series, beta=1.0): +def smooth_max(series: pd.Series, beta=1.0) -> float: return np.log(np.sum(np.exp(beta * series))) / beta -def smooth_min(series, beta=1.0): +def smooth_min(series: pd.Series, beta=1.0) -> float: return -np.log(np.sum(np.exp(-beta * series))) / beta