def worker(train_param): try: config = load_config() config["model_id"] = 0 # this is will be overridden when driven from UI print (train_param) if train_param is not None: config["model_id"] = int(train_param["model_id"]) config["input"]["stocks"] = train_param["stocks"] if "feature_number" in train_param: config["input"]["feature_number"] = int(train_param["feature_number"]) if "training_start_date" in train_param: config["input"]["training_start_time"] = train_param["training_start_date"] if "training_end_date" in train_param: config["input"]["training_end_time"] = train_param["training_end_date"] if "testing_start_date" in train_param: config["testing"]["testing_start_time"] = train_param["testing_start_date"] if "testing_end_date" in train_param: config["testing"]["testing_end_time"] = train_param["testing_end_date"] if "episode" in train_param: config["training"]["episode"] = int(train_param["episode"]) if "trading_cost" in train_param: config["input"]["trading_cost"] = float(train_param["trading_cost"]) train_id = ddpg_trading_train(config, DEBUG=False).train_model() model = ddpg_restore_model(train_id) model.restore() model.backtest() print("Finish work on %s", train_id) except Exception as e: print("Fatal error in training %s", train_param["stocks"]) report_model_progress(config["model_id"],info={"error": True, "message": str(e)})
for learning_rate in learning_rates: config = load_config() config[ "model_id"] = 0 #this is will be overridden when driven from UI config["input"][ "feature_number"] = feature_number config["input"][ "window_length"] = window_length config["input"][ "predictor_type"] = predictor_type config["input"][ "trading_cost"] = trading_cost config["training"]["episode"] = episode config["input"]["stocks"] = stock config["layers"][ "activation_function"] = activation_function config["training"][ "actor learning rate"] = 0.001 config["training"][ "critic learning rate"] = 0.001 config["training"]["buffer size"] = 100000 config["training"]["max_step"] = 0 config["training"]["batch size"] = 64 print(config) train_id = ddpg_trading_train( config, DEBUG=DEBUG).train_model() model = ddpg_restore_model(train_id) model.restore() model.backtest() print("Finish work on %s" % (train_id))
def run_model(train_id, start_date, end_date): model = ddpg_restore_model(train_id) model.restore() summary = model.backtest(start_date, end_date) return summary