diff --git a/config/hashing.py b/config/hashing.py index f62ea6d..1e8b7f2 100644 --- a/config/hashing.py +++ b/config/hashing.py @@ -20,7 +20,6 @@ def hash_data_config(data_config: dict) -> str: data_config["target_asset"].path + data_config["target_asset"].file_name, data_config["load_non_target_asset"], - data_config["start_date"], hash_feature_extractors(data_config["own_features"]), hash_feature_extractors(data_config["other_features"]), hash_feature_extractors(data_config["exogenous_features"]), diff --git a/config/presets.py b/config/presets.py index f54cc40..ed32eb0 100644 --- a/config/presets.py +++ b/config/presets.py @@ -54,6 +54,7 @@ def get_minimal_config() -> RawConfig: meta_models = ["LogisticRegression_two_class", "LGBM"] return RawConfig( + start_date="2021-01-01", dimensionality_reduction_ratio=0, n_features_to_select=0, initial_window_size=3800, @@ -71,7 +72,7 @@ def get_minimal_config() -> RawConfig: meta_models=meta_models, event_filter="none", event_filter_multiplier=3.5, - remove_overlapping_events=True, + remove_overlapping_events=False, labeling="two_class", forecasting_horizon=10, transaction_costs=0.002, diff --git a/data_loader/load.py b/data_loader/load.py index e32a27e..d846de1 100644 --- a/data_loader/load.py +++ b/data_loader/load.py @@ -11,20 +11,20 @@ from config.hashing import hash_data_config from .types import XDataFrame, ReturnSeries from diskcache import Cache -cache = Cache(".cachedir/data") +# cache = Cache(".cachedir/data") -def load_data(**kwargs) -> tuple[XDataFrame, ReturnSeries]: - hashed = hash_data_config(kwargs) - if hashed in cache: - return cache.get(hashed) - else: - return_value = __load_data(**kwargs) - cache[hashed] = return_value - return return_value +# def load_data(**kwargs) -> tuple[XDataFrame, ReturnSeries]: +# hashed = hash_data_config(kwargs) +# if hashed in cache: +# return cache.get(hashed) +# else: +# return_value = __load_data(**kwargs) +# cache[hashed] = return_value +# return return_value -def __load_data( +def load_data( assets: DataCollection, other_assets: DataCollection, exogenous_data: DataCollection, diff --git a/run_baseline.py b/run_baseline.py new file mode 100644 index 0000000..23377c2 --- /dev/null +++ b/run_baseline.py @@ -0,0 +1,69 @@ +from re import S +from typing import Optional + +from sklearn.model_selection import train_test_split + +from config.types import Config, RawConfig +from config.preprocess import preprocess_config +from config.presets import get_default_config, get_minimal_config + +from data_loader.load import load_data +from data_loader.process import check_data + +from labeling.process import label_data + +from sklearn.metrics import accuracy_score + + +def run_sklearn_pipeline(raw_config: RawConfig): + config = preprocess_config(raw_config) + run_sklearn_training(config) + + +def run_sklearn_training(config: Config): + + print("---> Load data, check for validity") + X, returns = load_data( + assets=config.assets, + other_assets=config.other_assets, + exogenous_data=config.exogenous_data, + target_asset=config.target_asset, + load_non_target_asset=config.load_non_target_asset, + own_features=config.own_features, + other_features=config.other_features, + exogenous_features=config.exogenous_features, + start_date=config.start_date, + ) + + assert check_data(X, config) == True, "Data is not valid." + + print("---> Filter for significant events when we want to trade, and label data") + events, X, y, forward_returns = label_data( + event_filter=config.event_filter, + event_labeller=config.labeling, + X=X, + returns=returns, + remove_overlapping_events=config.remove_overlapping_events, + ) + + X_train, X_test, y_train, y_test = train_test_split( + X, y, test_size=0.2, random_state=42, shuffle=False + ) + + print("---> Train directional models") + + for transformation in config.transformations: + X_train = transformation.fit_transform(X_train, y_train) + + for transformation in config.transformations: + X_test = transformation.transform(X_test) + + config.directional_model.fit(X_train, y_train) + preds = config.directional_model.predict(X_test) + print(accuracy_score(y_test, preds)) + + +if __name__ == "__main__": + run_sklearn_pipeline( + raw_config=get_minimal_config(), + )