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
def fit_time_scale(strategy_dictionary_input, search_iterations_local,
                   time_iterations):
    """ fit timescale variables"""

    toc = tic()
    counter = 0
    strategy_dictionary_optimum = []
    optimum_profit = -2

    while counter < time_iterations:

        strategy_dictionary_input = randomise_time_inputs(
            strategy_dictionary_input)

        strategy_dictionary_local,\
            fitting_dictionary_local,\
            fitting_inputs_local,\
            fitting_targets_local,\
            data_local,\
            test_profit\
            = random_search(
                strategy_dictionary_input,
                search_iterations_local,
                toc)

        if test_profit > optimum_profit:
            optimum_profit = test_profit
            strategy_dictionary_optimum = strategy_dictionary_local
            fitting_dictionary_optimum = fitting_dictionary_local

        counter += 1

    underlined_output('Best strategy fit')

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

    output_strategy_results(strategy_dictionary_optimum,
                            fitting_dictionary_optimum,
                            data_local,
                            toc,
                            momentum_dict=simple_momentum_comparison(
                                data_local, strategy_dictionary_optimum,
                                fitting_dictionary_optimum))

    return strategy_dictionary_optimum,\
        fitting_inputs_local,\
        fitting_targets_local,\
        data_local
Пример #3
0
    if strategy_dictionary['fit_time']:
        strategy_dictionary, fitting_dictionary, fitting_inputs, fitting_targets, data_to_predict = fit_time_scale(
            strategy_dictionary, search_iterations, time_iterations, toc)

    else:
        strategy_dictionary, fitting_dictionary, fitting_inputs, fitting_targets, data_to_predict, test_profit \
            = random_search(
            strategy_dictionary,
            search_iterations,
            toc)

    underlined_output('Best strategy fit')

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

    output_strategy_results(strategy_dictionary,
                            fitting_dictionary,
                            data_to_predict,
                            toc,
                            momentum_dict=simple_momentum_comparison(
                                data_to_predict, strategy_dictionary,
                                fitting_dictionary))

    underlined_output('Offset validation')
    offsets = np.linspace(0, 300, 5)

    offset_scan_validation(strategy_dictionary, data_to_predict,
                           fitting_inputs, fitting_targets, offsets)