2022-01-29 06:41:40 +01:00
|
|
|
from typing import Optional
|
2022-01-12 23:10:18 +01:00
|
|
|
|
2022-01-26 23:22:43 +01:00
|
|
|
from config.types import Config, RawConfig
|
2022-02-17 16:36:35 +01:00
|
|
|
from config.preprocess import preprocess_config
|
2022-01-26 23:22:43 +01:00
|
|
|
from config.presets import get_default_ensemble_config, get_lightweight_ensemble_config
|
|
|
|
|
|
|
|
|
|
from data_loader.load import load_data
|
|
|
|
|
from data_loader.process import check_data
|
|
|
|
|
|
|
|
|
|
from labeling.process import label_data
|
2022-01-12 23:10:18 +01:00
|
|
|
|
2022-01-23 18:37:43 +01:00
|
|
|
from reporting.wandb import launch_wandb, override_config_with_wandb_values
|
2022-01-12 23:10:18 +01:00
|
|
|
from reporting.reporting import report_results
|
2022-01-23 11:38:40 +01:00
|
|
|
from reporting.saving import save_models
|
2022-01-11 19:15:58 +01:00
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
from training.directional_training import train_directional_model
|
|
|
|
|
from training.bet_sizing import bet_sizing_with_meta_model
|
2022-01-29 06:41:40 +01:00
|
|
|
from training.types import PipelineOutcome
|
2022-01-12 23:10:18 +01:00
|
|
|
|
2021-12-28 22:50:09 +01:00
|
|
|
import ray
|
|
|
|
|
ray.init()
|
2021-12-20 17:49:11 +01:00
|
|
|
|
2022-01-05 18:35:52 +01:00
|
|
|
|
2022-01-29 06:41:40 +01:00
|
|
|
def run_pipeline(project_name:str, with_wandb: bool, sweep: bool, raw_config: RawConfig) -> tuple[PipelineOutcome, Config]:
|
2022-01-26 23:22:43 +01:00
|
|
|
wandb, config = __setup_config(project_name, with_wandb, sweep, raw_config)
|
2022-01-29 06:41:40 +01:00
|
|
|
pipeline_outcome = __run_training(config)
|
2022-02-17 16:36:35 +01:00
|
|
|
report_results(pipeline_outcome.directional_training.training.stats, pipeline_outcome.get_output_stats(), pipeline_outcome.get_output_weights(), config, wandb, sweep)
|
2022-01-29 06:41:40 +01:00
|
|
|
save_models(pipeline_outcome, config)
|
|
|
|
|
return pipeline_outcome, config
|
2022-01-05 18:35:52 +01:00
|
|
|
|
|
|
|
|
|
2022-01-26 23:22:43 +01:00
|
|
|
def __setup_config(project_name:str, with_wandb: bool, sweep: bool, raw_config: RawConfig) -> tuple[Optional[object], Config]:
|
2021-12-20 17:49:11 +01:00
|
|
|
wandb = None
|
|
|
|
|
if with_wandb:
|
2022-01-23 18:37:43 +01:00
|
|
|
wandb = launch_wandb(project_name=project_name, default_config=raw_config, sweep=sweep)
|
|
|
|
|
raw_config = override_config_with_wandb_values(wandb, raw_config)
|
|
|
|
|
config = preprocess_config(raw_config)
|
2021-12-20 14:01:14 +01:00
|
|
|
|
2022-01-23 18:37:43 +01:00
|
|
|
return wandb, config
|
2022-01-12 23:10:18 +01:00
|
|
|
|
|
|
|
|
|
2022-01-05 18:35:52 +01:00
|
|
|
|
2022-01-29 06:41:40 +01:00
|
|
|
def __run_training(config: Config) -> PipelineOutcome:
|
2022-01-12 23:10:18 +01:00
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
print("---> Load data, check for validity")
|
|
|
|
|
X, returns = load_data(
|
2022-01-23 18:37:43 +01:00
|
|
|
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,
|
|
|
|
|
)
|
2022-01-23 11:38:40 +01:00
|
|
|
|
2022-01-26 23:22:43 +01:00
|
|
|
assert check_data(X, config) == True, "Data is not valid."
|
|
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
print("---> Filter for significant events when we want to trade, and label data")
|
|
|
|
|
events, X, y, forward_returns = label_data(config.event_filter, config.labeling, X, returns)
|
2022-01-26 23:22:43 +01:00
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
print("---> Train directional models")
|
|
|
|
|
directional_training_outcome = train_directional_model(X, y, forward_returns, config, config.directional_model, from_index = None, preloaded_training_step = None)
|
2022-01-05 18:35:52 +01:00
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
print("---> Run bet sizing on directional model's output")
|
|
|
|
|
bet_sizing_outcomes = bet_sizing_with_meta_model(X, directional_training_outcome.training.predictions, y, forward_returns, config.meta_model, config, 'meta', None, None, None)
|
2022-01-29 06:41:40 +01:00
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
return PipelineOutcome(directional_training_outcome, bet_sizing_outcomes)
|
2021-12-20 14:01:14 +01:00
|
|
|
|
2021-12-20 17:49:11 +01:00
|
|
|
if __name__ == '__main__':
|
2022-02-17 16:36:35 +01:00
|
|
|
run_pipeline(project_name='price-prediction', with_wandb = False, sweep = False, raw_config=get_lightweight_ensemble_config())
|