Skip to content

Commit

Permalink
feat: allow shorter data history when using model for forecasts only …
Browse files Browse the repository at this point in the history
…and no training

Signed-off-by: ivelin <[email protected]>
  • Loading branch information
ivelin committed Sep 23, 2024
1 parent 561f5d3 commit 5c384d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion forecast.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion src/canswim/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions src/canswim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5c384d3

Please sign in to comment.