Ejemplo n.º 1
0
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)})
Ejemplo n.º 2
0
activation_functions = ["prelu"]  #["relu","tanh","leaky_relu","prelu"]
repeat_time = 1
feature_numbers = [5]
reward_functions = [2]
learning_rates = [0.001]

for stock in stocks:
    for predictor_type in predictor_types:
        for window_length in window_lengths:
            for trading_cost in trading_costs:
                for activation_function in activation_functions:
                    for episode in episodes:
                        for feature_number in feature_numbers:
                            for _ in range(repeat_time):
                                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"][
Ejemplo n.º 3
0
    def start_session(self):
        tf.reset_default_graph()
        tf_config = tf.ConfigProto(allow_soft_placement=True,
                                    log_device_placement=False,)
        # if self.device == "cpu":
        #     tf_config.gpu_options.per_process_gpu_memory_fraction = 0
        # else:
        #     tf_config.gpu_options.per_process_gpu_memory_fraction = 1
        tf_config.gpu_options.allow_growth = True
        sess = tf.Session(config = tf_config)
        tflearn.config.init_training_mode()
        return sess

    def close_session(self):
        self.sess.close()

if __name__ == '__main__':

    parser = build_parser()
    args = vars(parser.parse_args())
    pprint.pprint(args)

    if args['debug'] == 'True':
        DEBUG = True
    else:
        DEBUG = False

    model = ddpg_trading_train(load_config(), DEBUG = DEBUG)
    train_id = model.train_model()
    print(train_id)