feat(Models): added debug_future_lookahead, sped up LogisticRegression & DecisionTreeClassifier (#74)

* feat(Models): added `debug_future_lookahead`, sped up LogisticRegression & DecisionTreeClassifier

* feat(Training): added ability to train on expanding_window

* feat(Models): tuned some hyperparameters, added expanding_window to sweep config, fixed tests

* feat(Models): tune parameters of ensemble models

* fix(Config): use window size that works with ensembling
This commit is contained in:
Mark Aron Szulyovszky
2021-12-22 16:59:03 +01:00
committed by GitHub
parent 25b64f5a3d
commit 6ae8acf70e
11 changed files with 32 additions and 10 deletions
+3 -2
View File
@@ -5,8 +5,9 @@ from models.model_map import model_names_classification, model_names_regression
def get_default_config() -> tuple[dict, dict, dict]:
training_config = dict(
sliding_window_size = 150,
retrain_every = 20,
expanding_window = True,
sliding_window_size = 200,
retrain_every = 100,
scaler = 'minmax', # 'normalize' 'minmax' 'standardize' 'none'
include_original_data_in_ensemble = True,
)
+1
View File
@@ -8,6 +8,7 @@ dependencies:
- seaborn
- scikit-learn-intelex=2021.4.0
- ipython
- ipykernel
- scipy
- scikit-learn
- numba
@@ -1,4 +1,6 @@
from feature_extractors.feature_extractors import feature_lag, feature_mom, feature_ROC, feature_RSI, feature_STOD, feature_STOK, feature_vol, feature_day_of_month, feature_day_of_week, feature_month
from feature_extractors.feature_extractors import feature_lag, feature_mom, feature_ROC, feature_RSI, feature_STOD, feature_STOK, feature_vol, feature_day_of_month, feature_day_of_week, feature_month, feature_debug_future_lookahead
debug_future_lookahead = [('debug_future', feature_debug_future_lookahead, [1])]
lags = [('lag', feature_lag, [1,2,3,4,5,6,7,8,9])]
+4
View File
@@ -11,7 +11,11 @@ def __get_close_low_high(df: pd.DataFrame) -> tuple[pd.Series, pd.Series, pd.Ser
## Feature extractors
def feature_debug_future_lookahead(df: pd.DataFrame, period: int, is_log_return: bool) -> pd.Series:
return df['returns'].shift(-period)
def feature_lag(df: pd.DataFrame, period: int, is_log_return: bool) -> pd.Series:
assert period > 0
return df['returns'].shift(period)
def feature_day_of_week(df: pd.DataFrame, period: int, is_log_return: bool) -> pd.DataFrame:
+6 -6
View File
@@ -15,25 +15,25 @@ from models.naive import StaticNaiveModel
model_map = {
"regression_models": dict(
Lasso = SKLearnModel(Lasso(alpha=0.1, max_iter=1000)),
LR = SKLearnModel(LinearRegression(n_jobs=-1)),
Lasso = SKLearnModel(Lasso(alpha=100, random_state=1)),
Ridge = SKLearnModel(Ridge(alpha=0.1)),
BayesianRidge = SKLearnModel(BayesianRidge()),
KNN = SKLearnModel(KNeighborsRegressor(n_neighbors=25)),
AB = SKLearnModel(AdaBoostRegressor(random_state=1)),
LR = SKLearnModel(LinearRegression(n_jobs=-1)),
MLP = SKLearnModel(MLPRegressor(hidden_layer_sizes=(100,20), max_iter=1000)),
RF = SKLearnModel(RandomForestRegressor(n_jobs=-1)),
SVR = SKLearnModel(SVR(kernel='rbf', C=1e3, gamma=0.1)),
StaticNaive = StaticNaiveModel(),
),
"classification_models": dict(
LR= SKLearnModel(LogisticRegression(n_jobs=-1)),
LR= SKLearnModel(LogisticRegression(solver='liblinear', C=10, max_iter=1000)),
LDA= SKLearnModel(LinearDiscriminantAnalysis()),
KNN= SKLearnModel(KNeighborsClassifier()),
CART= SKLearnModel(DecisionTreeClassifier()),
CART= SKLearnModel(DecisionTreeClassifier(max_depth=15, random_state=1)),
NB= SKLearnModel(GaussianNB()),
AB= SKLearnModel(AdaBoostClassifier()),
RF= SKLearnModel(RandomForestClassifier(n_jobs=-1)),
AB= SKLearnModel(AdaBoostClassifier(n_estimators=15)),
RF= SKLearnModel(RandomForestClassifier(n_jobs=-1, max_depth=20)),
StaticMom= StaticMomentumModel(allow_short=True),
),
"classification_ensemble_models": dict(
+2
View File
@@ -40,6 +40,7 @@ def pipeline(project_name:str, wandb, sweep:bool, model_config:dict, training_co
target_returns = target_returns,
models = model_config['level_1_models'],
method = data_config['method'],
expanding_window = training_config['expanding_window'],
sliding_window_size = training_config['sliding_window_size'],
retrain_every = training_config['retrain_every'],
scaler = training_config['scaler'],
@@ -64,6 +65,7 @@ def pipeline(project_name:str, wandb, sweep:bool, model_config:dict, training_co
target_returns = target_returns,
models = model_config['level_2_models'],
method = data_config['method'],
expanding_window = training_config['expanding_window'],
sliding_window_size = training_config['sliding_window_size'],
retrain_every = training_config['retrain_every'],
scaler = training_config['scaler'],
+3
View File
@@ -11,6 +11,9 @@ metric:
parameters:
path :
value: 'data/'
expanding_window:
values: [True, False]
distribution: categorical
sliding_window_size:
values: [90, 130, 160, 180, 280, 380]
distribution: categorical
+1
View File
@@ -68,6 +68,7 @@ def test_evaluation():
X=X,
y=y,
target_returns=y,
expanding_window=False,
window_size=window_length,
retrain_every=10,
scaler=scaler
+1
View File
@@ -65,6 +65,7 @@ def test_walk_forward_train_test():
X=X,
y=y,
target_returns=y,
expanding_window=False,
window_size=window_length,
retrain_every=10,
scaler=scaler)
+2
View File
@@ -22,6 +22,7 @@ def run_single_asset_trainig(
target_returns: pd.Series,
models: list[tuple[str, Model]],
method: Literal['regression', 'classification'],
expanding_window: bool,
sliding_window_size: int,
retrain_every: int,
scaler: Literal['normalize', 'minmax', 'standardize', 'none'],
@@ -45,6 +46,7 @@ def run_single_asset_trainig(
X = X,
y = y,
target_returns = target_returns,
expanding_window = expanding_window,
window_size = sliding_window_size,
retrain_every = retrain_every,
scaler = scaler
+6 -1
View File
@@ -11,6 +11,7 @@ def walk_forward_train_test(
X: pd.DataFrame,
y: pd.Series,
target_returns: pd.Series,
expanding_window: bool,
window_size: int,
retrain_every: int,
scaler,
@@ -35,7 +36,11 @@ def walk_forward_train_test(
for index in range(train_from, train_till):
if iterations_before_retrain <= 0 or pd.isna(models[index-1]):
train_window_start = index - window_size - 1
if expanding_window:
train_window_start = first_nonzero_return
else:
train_window_start = index - window_size - 1
train_window_end = index - 1
if is_scaling_on: