test_indices, [],
                                                    price_array_training,
                                                    price_array, **cnn_kwargs)

        print(fitting_dictionary['fitted_strategy_score'])

        if len(portfolio_allocations) != 0:
            portfolio_allocations = np.vstack([
                portfolio_allocations,
                fitting_dictionary['fitted_strategy_score']
            ])
        else:
            portfolio_allocations = fitting_dictionary['fitted_strategy_score']

        plot_portfolio_value, cum_log_return = calculate_portfolio_value(
            portfolio_allocations, price_array[initial_idx:(idx + 1), :],
            liquidation_factor[(initial_idx + 1):(idx + 1), :])

        print('Backtest step ', idx - initial_idx, ' of ', run_length)
        if len(plot_portfolio_value) != 0:
            print('Cumulative profit fraction:', plot_portfolio_value[-1] - 1)
        print()

        if plot_time:
            plot_time.append(plot_time[-1] + 1 / 48.0)
        else:
            plot_time.append(1 / 48.0)

        plot_prices = np.cumprod(price_array[initial_idx:(idx + 1), 0], axis=0)

        other_prices = np.cumprod(price_array[initial_idx:(idx + 1), :],
예제 #2
0
        #    [0.9, 0.05, 0.0001])

        train_indices = np.linspace(0, len(price_array_training)-100, len(price_array_training)-100, dtype=int)
        test_indices = np.linspace(len(price_array_training) - 100, len(price_array_training) - 75, 25, dtype=int)
        validation_indices = np.linspace(len(price_array_training) -5, len(price_array_training)-1, 5, dtype=int)

        fitting_dictionary = tensorflow_cnn_fitting(
            train_indices,
            test_indices,
            validation_indices,
            price_array_training,
            price_array,
            load_net='model.h5')

        portfolio_value, cum_log_return = calculate_portfolio_value(
            fitting_dictionary['fitted_strategy_score'],
            price_array[test_indices, :])

        final_portfolio_value = portfolio_value[-1]
        running_portfolio_value *= final_portfolio_value

        print('Run profit fraction: ', final_portfolio_value - 1)
        print('Offset tests cumulative profit fraction:', running_portfolio_value - 1)

        from matplotlib import pyplot as plt
        plt.figure()
        plt.plot(portfolio_value)
        plt.xlabel('Time (30 minute steps)')
        plt.ylabel('Fractional Portfolio Value')

        plt.figure()