From 5c384d3460f44944fdafa25bf65dae98a2e53f85 Mon Sep 17 00:00:00 2001 From: ivelin <ivelin117@gmail.com> Date: Sun, 22 Sep 2024 20:29:41 -0500 Subject: [PATCH] feat: allow shorter data history when using model for forecasts only and no training Signed-off-by: ivelin <ivelin117@gmail.com> --- forecast.sh | 3 ++- src/canswim/forecast.py | 2 +- src/canswim/model.py | 10 ++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/forecast.sh b/forecast.sh index 152b537..934b747 100755 --- a/forecast.sh +++ b/forecast.sh @@ -39,4 +39,5 @@ set -exv #./canswim.sh forecast --forecast_start_date "2024-08-26" #./canswim.sh forecast --forecast_start_date "2024-09-02" #./canswim.sh forecast --forecast_start_date "2024-09-09" -./canswim.sh forecast --forecast_start_date "2024-09-16" +#./canswim.sh forecast --forecast_start_date "2024-09-16" +./canswim.sh forecast --forecast_start_date "2024-09-23" diff --git a/src/canswim/forecast.py b/src/canswim/forecast.py index 1580454..338c4c6 100644 --- a/src/canswim/forecast.py +++ b/src/canswim/forecast.py @@ -24,7 +24,7 @@ def __init__(self): logger.info(f"n_stocks: {self.n_stocks}") self.forecast_subdir = os.getenv("forecast_subdir", "forecast/") logger.info(f"Forecast data path: {self.forecast_subdir}") - self.canswim_model = CanswimModel() + self.canswim_model = CanswimModel(forecast_only=True) self.hfhub = HFHub() def download_model(self): diff --git a/src/canswim/model.py b/src/canswim/model.py index b43c68f..ff87d8e 100644 --- a/src/canswim/model.py +++ b/src/canswim/model.py @@ -39,7 +39,8 @@ def optuna_print_callback(study, trial): class CanswimModel: - def __init__(self): + def __init__(self, forecast_only=False): + self.forecast_only = forecast_only self.n_stocks: int = 50 self.n_epochs: int = 10 self.train_series = {} @@ -76,7 +77,12 @@ def n_test_range_days(self): def min_samples(self): # minimum amount of historical data required to train on a stock series # stocks that are too new off IPOs, are not a good fit for training this model - m = self.n_test_range_days * 3 + # m = self.n_test_range_days * 3 + # update Sep 11, 2024: + # min required samples for training and forecast encompasses the lookback history window plus val prediction window plus test prediction window + m = self.train_history + self.pred_horizon + self.pred_horizon + if not self.forecast_only: + m += self.train_history return m @property