From 0aa6ecea9cbdb524eee669d8cdb5f2daa61abc05 Mon Sep 17 00:00:00 2001 From: FaritSharafutdinov Date: Sun, 20 Jul 2025 13:30:37 +0300 Subject: [PATCH 1/2] Update forecasting_models.py --- ml/forecasting_models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ml/forecasting_models.py b/ml/forecasting_models.py index 8219b92..7df6276 100644 --- a/ml/forecasting_models.py +++ b/ml/forecasting_models.py @@ -1160,9 +1160,9 @@ def predict(self, date_range: pd.DatetimeIndex, initial_price: float = None) -> history_df = self.df_.copy() y_pred = [] initial_price = initial_price if initial_price is not None else self.last_close_price - max_volatility = initial_price * 0.03 # 3% от начальной цены за 48 часов - max_step_change = initial_price * 0.001 # 0.1% за шаг (30 минут) - min_price = initial_price * 0.9 # Минимальная цена (90% от начальной) + max_volatility = initial_price * 0.02 # 3% от начальной цены за 48 часов + max_step_change = initial_price * 0.0003 # 0.1% за шаг + min_price = initial_price * 0.93 # Минимальная цена for idx, date in enumerate(date_range): feature_columns = [column for column in prediction_df.columns if column != 'Close'] From 91e92b474626044cb9cc581a6e6524d11e6b5be6 Mon Sep 17 00:00:00 2001 From: FaritSharafutdinov Date: Sun, 20 Jul 2025 14:29:04 +0300 Subject: [PATCH 2/2] Update forecasting_models.py --- ml/forecasting_models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ml/forecasting_models.py b/ml/forecasting_models.py index 7df6276..5ba5633 100644 --- a/ml/forecasting_models.py +++ b/ml/forecasting_models.py @@ -1169,7 +1169,9 @@ def predict(self, date_range: pd.DatetimeIndex, initial_price: float = None) -> features = prediction_df.loc[date, feature_columns].copy() x_ = compose_forecast_frame(history_df.to_numpy(), features.to_numpy(), self.lag) y_ = self.model_.predict(x_)[0] - + if idx > 0: + alpha = 0.05 # Коэффициент сглаживания (0 < alpha < 1, меньшие значения - более плавное сглаживание) + y_ = alpha * y_ + (1 - alpha) * y_pred[-1] # Умеренные колебания atr = features['ATR14'] if 'ATR14' in features else 0.05 noise = np.random.normal(0, atr * 0.02) # Очень слабый шум @@ -1220,7 +1222,9 @@ def predict(self, date_range: pd.DatetimeIndex, initial_price: float = None) -> history_df = history_df.loc[~history_df.index.duplicated(keep='last')] y_pred = pd.Series(y_pred, index=date_range) - price_prediction = initial_price + np.cumsum(y_pred) + smoothed_y_pred = y_pred.rolling(window=5, center=True, min_periods=1).mean() # Скользящее среднее с окном 5 + + price_prediction = initial_price + np.cumsum(smoothed_y_pred) return price_prediction def dump(self, path: str) -> None: