Beispiel #1
0
    def train(self, data: DataFrame):
        """
        Train networks to the data (OHLC) passed
        :param data: Data in OHLC format from the ticks module.
        :return: the NN trained, and the encoder used
        """
        # Remove the "Date" Column
        ticks = data.copy(deep=True).drop([self.params.csv_dict['d']], axis=1)
        # Train
        encoder = CSEncoder(self.params).fit(ticks)
        cse = encoder.ticks2cse(ticks)
        dataset = self.prepare_input(encoder, cse, self.params.subtypes)
        nn = self.train_nn(dataset, self.params.subtypes)
        encoder.save()

        return nn, encoder
Beispiel #2
0
tf.compat.v1.logging.set_verbosity(tf.logging.ERROR)
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

np.random.seed(1)
params = Params(args=sys.argv)
log = CSLogger(params._log_level)
ticks = Ticks()
ohlc_data = ticks.read_ohlc()

if params.do_train is True:
    encoder = CSEncoder().fit(ohlc_data)
    cse = encoder.ticks2cse(ohlc_data)
    dataset = split_datasets(encoder, cse, params.subtypes)
    nn = train_nn(dataset, params.subtypes)
    encoder.save()
else:
    nn = load_nn(params.model_names, params.subtypes)
    encoder = load_encoders(params.model_names)
    predictions = pd.DataFrame([])

    if params._predict_training:
        # for from_idx in range(0, ticks.shape[0] - params._window_size + 1):
        for from_idx in range(0, 50 - params._window_size + 1):
            tick_group = ohlc_data.iloc[from_idx:from_idx +
                                        params._window_size]
            prediction = single_prediction(tick_group, nn, encoder, params)
            prediction = add_supervised_info(
                prediction,
                ohlc_data.iloc[from_idx + params._window_size]['c'], params)
            predictions = predictions.append(prediction)