def random_search(strategy_dictionary_local, n_iterations):
    toc = tic()

    data_local, data_2 = import_data(strategy_dictionary)
    fitting_inputs_local, continuous_targets, classification_targets = input_processing(
        data_local, data_2, strategy_dictionary)

    counter = 0
    error = 1e5
    while counter < n_iterations:
        counter += 1
        strategy_dictionary_local = randomise_dictionary_inputs(strategy_dictionary_local)

        if strategy_dictionary['regression_mode'] == 'classification':
            fitting_targets_local = classification_targets
        elif strategy_dictionary['regression_mode'] == 'regression':
            fitting_targets_local = continuous_targets

        fitting_inputs_local = preprocessing_inputs(strategy_dictionary, fitting_inputs_local)

        fitting_dictionary, profit_factor = fit_strategy(
            strategy_dictionary, data_local, fitting_inputs_local, fitting_targets_local)
        error_loop = fitting_dictionary['error']

        if error_loop < error and fitting_dictionary['n_trades'] != 0:
            error = error_loop
            strategy_dictionary_local_optimum = strategy_dictionary_local
            fitting_dictionary_optimum = fitting_dictionary

    underlined_output('Best strategy fit')
    output_strategy_results(strategy_dictionary_local_optimum, fitting_dictionary_optimum, data_local, toc)

    return strategy_dictionary_local_optimum, fitting_inputs_local, fitting_targets_local, data_local
def tensorflow_fitting(strategy_dictionary_local):
    toc = tic()
    data_local = import_data(strategy_dictionary_local)
    fitting_inputs_local, continuous_targets, classification_targets = input_processing(
        data_local, strategy_dictionary)

    if strategy_dictionary_local['regression_mode'] == 'classification':
        fitting_targets_local = classification_targets
    elif strategy_dictionary_local['regression_mode'] == 'regression':
        fitting_targets_local = continuous_targets

    fitting_inputs_local, strategy_dictionary_local = preprocessing_inputs(
        strategy_dictionary_local, fitting_inputs_local)

    fitting_dictionary, error_loop, profit_factor = fit_tensorflow(
        strategy_dictionary_local, data_local, fitting_inputs_local,
        fitting_targets_local)

    if strategy_dictionary_local['plot_last']:
        strategy_dictionary_local['plot_flag'] = True

    output_strategy_results(strategy_dictionary_local,
                            fitting_dictionary,
                            data_local,
                            toc,
                            momentum_dict=simple_momentum_comparison(
                                data_local, strategy_dictionary,
                                fitting_dictionary))

    output_strategy_results(strategy_dictionary, fitting_dictionary,
                            data_local, toc)

    return strategy_dictionary, data_local, fitting_inputs_local, fitting_targets_local
Пример #3
0
def random_search(strategy_dictionary_local, n_iterations):
    print("Ticking")
    toc = tic()
    print("Importing data")
    data_local, data_2 = import_data(strategy_dictionary_local)
    print("Finished Imported data")

    fitting_inputs_local, continuous_targets, classification_targets = input_processing(
        data_local, data_2, strategy_dictionary)
    print("Targets determined")

    counter = 0
    error = 1e5
    fitting_dictionary_optimum = []
    strategy_dictionary_optimum = []
    fitting_targets_local = []
    while counter < n_iterations:
        print("Starting iteration %s" % counter)
        counter += 1

        # strategy_dictionary['sequence_flag'] = np.random.choice([True, False])
        strategy_dictionary['sequence_flag'] = False

        if strategy_dictionary['sequence_flag']:
            strategy_dictionary_local = randomise_sequence_dictionary_inputs(
                strategy_dictionary_local)
        else:
            strategy_dictionary_local = randomise_dictionary_inputs(
                strategy_dictionary_local)

        if strategy_dictionary_local['regression_mode'] == 'classification':
            fitting_targets_local = classification_targets
        elif strategy_dictionary_local['regression_mode'] == 'regression':
            fitting_targets_local = continuous_targets

        fitting_inputs_local, strategy_dictionary_local = preprocessing_inputs(
            strategy_dictionary_local, fitting_inputs_local)

        fitting_dictionary, error_loop, profit_factor = fit_tensorflow(
            strategy_dictionary_local, data_local, fitting_inputs_local,
            fitting_targets_local)

        if error_loop < error:
            error = error_loop
            strategy_dictionary_optimum = strategy_dictionary_local
            fitting_dictionary_optimum = fitting_dictionary
        print("Completed iteration")

    underlined_output('Best strategy fit')
    output_strategy_results(strategy_dictionary_optimum,
                            fitting_dictionary_optimum, data_local, toc)

    return strategy_dictionary_optimum, data_local, fitting_inputs_local, fitting_targets_local
Пример #4
0
def random_search(strategy_dictionary_local, n_iterations, toc):
    """random search to find optimum machine learning algorithm and preprocessing"""

    data_local = import_data(strategy_dictionary_local)
    fitting_inputs_local, continuous_targets, classification_targets = input_processing(
        data_local, strategy_dictionary_local)

    counter = 0
    error = 1e5
    fitting_targets_local = []
    fitting_dictionary_optimum = []
    strategy_dictionary_optimum = []
    while counter < n_iterations:
        counter += 1
        strategy_dictionary_local = randomise_dictionary_inputs(
            strategy_dictionary_local)

        if strategy_dictionary_local['regression_mode'] == 'classification':
            fitting_targets_local = classification_targets.astype(int)
        elif strategy_dictionary_local['regression_mode'] == 'regression':
            fitting_targets_local = continuous_targets

        fitting_inputs_local, strategy_dictionary_local = preprocessing_inputs(
            strategy_dictionary_local, fitting_inputs_local)

        fitting_dictionary_local, _, _, strategy_dictionary_local = fit_strategy(
            strategy_dictionary_local, data_local, fitting_inputs_local,
            fitting_targets_local)

        error_loop = fitting_dictionary_local['error']

        if error_loop < error and fitting_dictionary_local['n_trades'] != 0:
            error = error_loop
            strategy_dictionary_optimum = strategy_dictionary_local
            fitting_dictionary_optimum = fitting_dictionary_local

    if strategy_dictionary_optimum:
        profit, test_profit = output_strategy_results(
            strategy_dictionary_optimum, fitting_dictionary_optimum,
            data_local, toc)

    else:
        test_profit = -2

    return strategy_dictionary_optimum,\
        fitting_dictionary_optimum,\
        fitting_inputs_local,\
        fitting_targets_local,\
        data_local,\
        test_profit
def random_search(strategy_dictionary_local, n_iterations):
    toc = tic()
    data_local, data_2 = import_data(strategy_dictionary_local)
    fitting_inputs_local, continuous_targets, classification_targets = input_processing(
        data_local, data_2, strategy_dictionary)

    counter = 0
    error = 1e5
    fitting_dictionary_optimum = []
    strategy_dictionary_optimum = []
    fitting_targets_local = []
    while counter < n_iterations:
        counter += 1

        strategy_dictionary['sequence_flag'] = np.random.choice([True, False])

        if strategy_dictionary['sequence_flag']:
            strategy_dictionary_local = randomise_sequence_dictionary_inputs(
                strategy_dictionary_local)
        else:
            strategy_dictionary_local = randomise_dictionary_inputs(
                strategy_dictionary_local)

        if strategy_dictionary_local['regression_mode'] == 'classification':
            fitting_targets_local = classification_targets
        elif strategy_dictionary_local['regression_mode'] == 'regression':
            fitting_targets_local = continuous_targets

        fitting_inputs_local, strategy_dictionary_local = preprocessing_inputs(
            strategy_dictionary_local, fitting_inputs_local)

        fitting_dictionary, error_loop, profit_factor = fit_tensorflow(
            strategy_dictionary_local, data_local, fitting_inputs_local,
            fitting_targets_local)

        if error_loop < error:
            error = error_loop
            strategy_dictionary_optimum = strategy_dictionary_local
            fitting_dictionary_optimum = fitting_dictionary

    underlined_output('Best strategy fit')
    output_strategy_results(strategy_dictionary_optimum,
                            fitting_dictionary_optimum, data_local, toc)

    return strategy_dictionary_optimum, data_local, fitting_inputs_local, fitting_targets_local
def random_search(strategy_dictionary_local, n_iterations):
    """random search to find optimum machien learning algorithm and preprocessing"""

    toc = tic()

    data_local = import_data(strategy_dictionary_local)
    fitting_inputs_local, continuous_targets, classification_targets = input_processing(
        data_local, strategy_dictionary_local)

    counter = 0
    error = 1e5
    fitting_targets_local = []
    fitting_dictionary_optimum = []
    strategy_dictionary_optimum = []
    while counter < n_iterations:
        counter += 1
        strategy_dictionary_local = randomise_dictionary_inputs(
            strategy_dictionary_local)

        if strategy_dictionary_local['regression_mode'] == 'classification':
            fitting_targets_local = classification_targets.astype(int)
        elif strategy_dictionary_local['regression_mode'] == 'regression':
            fitting_targets_local = continuous_targets

        fitting_inputs_local, strategy_dictionary = preprocessing_inputs(
            strategy_dictionary_local, fitting_inputs_local)

        fitting_dictionary, profit_factor = fit_strategy(
            strategy_dictionary, data_local, fitting_inputs_local,
            fitting_targets_local)

        error_loop = fitting_dictionary['error']

        if error_loop < error and fitting_dictionary['n_trades'] != 0:
            error = error_loop
            strategy_dictionary_optimum = strategy_dictionary_local
            fitting_dictionary_optimum = fitting_dictionary

    underlined_output('Best strategy fit')
    output_strategy_results(strategy_dictionary_optimum,
                            fitting_dictionary_optimum, data_local, toc)

    return strategy_dictionary_optimum, fitting_inputs_local, fitting_targets_local, data_local
Пример #7
0
def tensorflow_fitting(strategy_dictionary_local):
    toc = tic()
    data_local, data_2 = import_data(strategy_dictionary_local)
    fitting_inputs_local, continuous_targets, classification_targets = input_processing(
        data_local, data_2, strategy_dictionary)

    if strategy_dictionary_local['regression_mode'] == 'classification':
        fitting_targets_local = classification_targets
    elif strategy_dictionary_local['regression_mode'] == 'regression':
        fitting_targets_local = continuous_targets

    fitting_inputs_local, strategy_dictionary_local = preprocessing_inputs(
        strategy_dictionary_local, fitting_inputs_local)

    fitting_dictionary, error_loop, profit_factor = fit_tensorflow(
        strategy_dictionary_local, data_local, fitting_inputs_local,
        fitting_targets_local)

    underlined_output('Best strategy fit')
    output_strategy_results(strategy_dictionary, fitting_dictionary,
                            data_local, toc)

    return strategy_dictionary, data_local, fitting_inputs_local, fitting_targets_local