Ejemplo n.º 1
0
def test_batcher():
    data = {
        'col1CLS': [3, 3, 4, 5, 7, 8, 7, 6, 5, 4],
        'col2CLS': [6, 5, 5, 6, 7, 6, 4, 3, 3, 8],
        'col3CLS': [7, 6, 4, 6, 4, 2, 4, 5, 6, 5],
        'col4CLS': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        'col5CLS': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        'col1CHG': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        'col2CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col3CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col4CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col5CHG': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        'col2slope_sum': [13, 8, -3, 3, 3, 3, 3, 3, 3, 3],
        'col3slope_sum': [1, -3, 3, 5, 3, 3, 3, 3, 3, 3],
        'col4slope_sum': [9, 3, 9, 3, -3, 3, 3, 3, 3, 3],
    }
    stock_data = pd.DataFrame(data=data)

    print sample_slopes.generate_target_values(stock_data, 3, "col2CLS", 2)

    assert len(
        sample_slopes.create_batch_of_slopes(stock_data, 'col4slope_sum', 2,
                                             6)) == 6
    assert sample_slopes.create_batch_of_slopes(stock_data, 'col4slope_sum', 2,
                                                6) == [
                                                    [9, 3],
                                                    [3, 9],
                                                    [9, 3],
                                                    [3, -3],
                                                    [-3, 3],
                                                    [3, 3],
                                                ]
Ejemplo n.º 2
0
def test_train_on_test_data():

    data = {'col1CLS': [3, 3, 4, 5, 7, 8, 7, 6, 5, 4],
            'col2CLS': [6, 5, 5, 6, 7, 6, 4, 3, 3, 8],
            'col3CLS': [7, 6, 4, 6, 4, 2, 4, 5, 6, 5],
            'col4CLS': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            'col5CLS': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
            'col1CHG': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            'col2CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            'col3CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            'col4CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            'col5CHG': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
            'col2slope_sum': [13, 8, -3, 3, 3, 3, 3, 3, 3, 3],
            'col3slope_sum': [1, -3, 3, 5, 3, 3, 3, 3, 3, 3],
            'col4slope_sum': [9, 3, 9, 3, -3, 7, -14, 3, 99, 3],
            }
    stock_data = pd.DataFrame(data=data)

    # generate_target_values(df, batch_count, column_name, look_ahead)
    y_values = sample_slopes.generate_target_values(
        stock_data, 3, 'col2CLS', 2)

    # create_batch_of_slopes(df, batch_count, cut_length)
    x_vaules = sample_slopes.create_batch_of_slopes(
        stock_data, 'col2slope_sum', 3,   y_values[1])

    print x_vaules, 'x values'
    print y_values[0], ' yvalues'

    sv = support_vector.Support_Vector(x_vaules, y_values[0])
    sv.train()
    assert sv.predict_out_put([[-0.8, -1, 0]]) == [-1] or [1]
    print "it was warnred "
Ejemplo n.º 3
0
def test_different_lengths_of_objects():
    """
    This test is used to try out the returns calculator on the stock market data

    """

    ticker = 'FB'

    main_df = pd.read_pickle(settings.settings_dict['stock_data_path'])
    main_df = sample_slopes.create_slope_sum(main_df)

    Back_Test = back_test.BackTest(main_df,
                                   settings.settings_dict['model_path'])

    y_values = sample_slopes.generate_target_values(main_df, 18,
                                                    ticker + "CLS", 2)

    x_values = sample_slopes.create_batch_of_slopes(main_df, ticker + 'CLS',
                                                    18, y_values[1])

    array_of_batches = Back_Test.create_batch_of_slopes(
        main_df, ticker + 'slope_sum', 18, y_values[1])

    print array_of_batches, ' here is len of array_of_batch'

    print Back_Test.append_list_of_buy_sells(array_of_batches,
                                             ticker + "slope_sum")

    print "algorithm dfa ", sum(
        Back_Test.take_bid_stream_calculate_profit(ticker + "bid_stream", 18,
                                                   2)), ' alogritmsss'
    print "percent change", Back_Test.calculate_holding_profit(
        ticker + "CLS", 18, 2),
Ejemplo n.º 4
0
def test_on_market_data_single_stock():
    """
    This test is used to try out the returns calculator on the stock market data

    """

    main_df = pd.read_pickle(settings.settings_dict['stock_data_path'])
    main_df = sample_slopes.create_slope_sum(main_df)

    Back_Test = back_test.BackTest(main_df,
                                   settings.settings_dict['model_path'])

    y_values = sample_slopes.generate_target_values(main_df, 18, 'FBCLS', 2)

    x_values = sample_slopes.create_batch_of_slopes(main_df, 'FBCLS', 18,
                                                    y_values[1])

    array_of_batches = Back_Test.create_batch_of_slopes(
        main_df, 'FBslope_sum', 18, y_values[1])

    print array_of_batches, ' here is lensss'

    print Back_Test.append_list_of_buy_sells(array_of_batches, "FBslope_sum")

    print "algorithm ", sum(
        Back_Test.take_bid_stream_calculate_return("FBbid_stream", 18,
                                                   2)) * 100, '%'
    print "log return ", sum(
        Back_Test.test_calculate_holding_log_return('FBCLS')) * 100, '%'
    print "percent change", Back_Test.calculate_holding_percent_change_return(
        "FBCLS") * 100, '%'
Ejemplo n.º 5
0
def test_generate_target_values_and_sliding_window_lenth():

    data = {
        'col1CLS': [3, 3, 4, 5, 7, 8, 7, 6, 5, 4],
        'col2CLS': [6, 5, 5, 6, 7, 6, 4, 3, 3, 8],
        'col3CLS': [7, 6, 4, 6, 4, 2, 4, 5, 6, 5],
        'col4CLS': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        'col5CLS': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        'col1CHG': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        'col2CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col3CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col4CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col5CHG': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        'col2slope_sum': [13, 8, -3, 3, 3, 3, 3, 3, 3, 3],
        'col3slope_sum': [1, -3, 3, 5, 3, 3, 3, 3, 3, 3],
        'col4slope_sum': [9, 3, 9, 3, -3, 3, 3, 3, 3, 3],
    }
    stock_data = pd.DataFrame(data=data)

    # generate_target_values(df, batch_count, column_name, look_ahead)
    y_values = sample_slopes.generate_target_values(stock_data, 2, 'col4CLS',
                                                    2)

    # create_batch_of_slopes(df, batch_count, cut_length)
    x_vaules = sample_slopes.create_batch_of_slopes(stock_data,
                                                    'col4slope_sum', 2,
                                                    y_values[1])

    print(y_values[0]), 'len y ', len(y_values[0])
    print(x_vaules), 'len x ', len(x_vaules)

    assert len(y_values[0]) == len(x_vaules)

    y_values = sample_slopes.generate_target_values(stock_data, 3, 'col4CLS',
                                                    3)

    # create_batch_of_slopes(df, batch_count, cut_length)
    x_vaules = sample_slopes.create_batch_of_slopes(stock_data,
                                                    'col4slope_sum', 3,
                                                    y_values[1])

    print(y_values[0]), 'len y ', len(y_values[0])
    print(x_vaules), 'len x ', len(x_vaules)

    assert len(y_values[0]) == len(x_vaules)
Ejemplo n.º 6
0
def test_iterate_and_persist_slope_sums():
    """
    used to make sure that i can make the logic to maintain the congruency between
    featcures and targetvalues across all slope_sum_cols
    """

    data = {'col1CLS': [3, 3, 4, 5, 7, 8, 7, 6, 5, 4],
            'col2CLS': [6, 5, 5, 6, 7, 6, 4, 3, 3, 8],
            'col3CLS': [7, 6, 4, 6, 4, 2, 4, 5, 6, 5],
            'col4CLS': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            'col5CLS': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
            'col1CHG': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            'col2CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            'col3CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            'col4CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
            'col5CHG': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
            'col2slope_sum': [13, 8, -3, 3, 3, 3, 3, 3, 3, 3],
            'col3slope_sum': [1, -3, 3, 5, 3, 3, 3, 3, 3, 3],
            'col4slope_sum': [9, 3, 9, 3, -3, 7, -14, 3, 99, 3],
            }
    stock_data = pd.DataFrame(data=data)

    columns = list(stock_data)

    columns_with_sample_slopes = sample_slopes.get_columns_with_slope_sum(
        columns)

    sv = support_vector.Support_Vector([], [])

    for column in columns_with_sample_slopes:

        y_values = sample_slopes.generate_target_values(
            stock_data, 3, column.replace('slope_sum', 'CLS'), 2)
        sv.Y = sv.Y + y_values[0]

        # create_batch_of_slopes(df, batch_count, cut_length)
        # y_values[1] bec thats used to tell create batch_of_slopes where to
        # stop
        x_values = sample_slopes.create_batch_of_slopes(
            stock_data, column, 3,   y_values[1])

        sv.X = sv.X + x_values

    print sv.X, 'xvalues'
    print sv.Y, 'yvalues'
    sv.train()
    assert sv.predict_out_put([[9, 3, -3]]) == [1]

    test_data = [[1.00893849384939849, 2, 3], [9, 3, -3], [-1, 5, 3],
                 [8, -3, 3], [-3, 3, 3], [3, 3, 3], [3, 3, 3], ]
    for sample in test_data:
        print sv.predict_out_put([sample])
Ejemplo n.º 7
0
def test_generate_target_values():
    data = {
        'col1CLS': [3, 3, 4, 5, 7, 8, 7, 6, 5, 4],
        'col2CLS': [6, 5, 5, 6, 7, 6, 4, 3, 3, 8],
        'col3CLS': [7, 6, 4, 6, 4, 2, 4, 5, 6, 5],
        'col4CLS': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        'col5CLS': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        'col1CHG': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        'col2CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col3CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col4CHG': [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        'col5CHG': [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        'col2slope_sum': [13, 8, -3, 3, 3, 3, 3, 3, 3, 3],
        'col3slope_sum': [1, -3, 3, 5, 3, 3, 3, 3, 3, 3],
        'col4slope_sum': [9, 3, 9, 3, -3, 3, 3, 3, 3, 3],
    }
    stock_data = pd.DataFrame(data=data)

    assert sample_slopes.generate_target_values(stock_data, 3, 'col2CLS',
                                                2) == ([1, 1, -1, -1, -1,
                                                        1], 6)
    assert sample_slopes.generate_target_values(stock_data, 3, 'col3CLS',
                                                2) == ([1, -1, 1, 1, 1, 1], 6)
Ejemplo n.º 8
0
def test_on_array_of_market():
    """
    This test is used to try out the returns calculator on the stock market data

    """
    tickers = [
        "GOOG", "FB", "INTC", 'TSM', "CSCO", "ORCL", "NVDA", "SAP", "IBM",
        "ADBE", "TXN", "AVGO", "CRM", "QCOM", "MU", "BIDU", "ADP", "VMW",
        "ATVI", "AMAT", "INTU", "CTSH", "EA", "EA", "NXPI", "INFY"
    ]

    # tickers = ["GOOG", "FB", "INTC", 'TSM', "CSCO"]

    main_df = pd.read_pickle(settings.settings_dict['stock_data_path'])
    main_df = sample_slopes.create_slope_sum(main_df)

    Back_Test = back_test.BackTest(main_df,
                                   settings.settings_dict['model_path'])

    with open('files/testing_files/return_output.csv', 'w') as f:
        for ticker in tickers:

            y_values = sample_slopes.generate_target_values(
                main_df, 18, ticker + "CLS", 2)

            x_values = sample_slopes.create_batch_of_slopes(
                main_df, ticker + 'CLS', 18, y_values[1])

            array_of_batches = Back_Test.create_batch_of_slopes(
                main_df, ticker + 'slope_sum', 18, y_values[1])

            Back_Test.append_list_of_buy_sells(array_of_batches,
                                               ticker + "slope_sum")

            algorithm_return = sum(
                Back_Test.take_bid_stream_calculate_return(
                    ticker + "bid_stream", 18, 2)) * 100
            log_return = sum(
                Back_Test.test_calculate_holding_log_return(ticker +
                                                            'CLS')) * 100
            percent_change = Back_Test.calculate_holding_percent_change_return(
                ticker + "CLS") * 100

            print "algorithm ", algorithm_return, '%'
            print "log return ", log_return, ' %'
            print "percent change", percent_change, '%'

            f.write(ticker + ',' + str(algorithm_return) + ',' +
                    str(log_return) + ',' + str(percent_change) + '\n')
Ejemplo n.º 9
0
def main(batch_size, look_ahead):
    """
    da main function
    """
    i = 0
    main_df = pd.DataFrame()

    ticker_data = Ticker_Data(main_df)

    # NOTE ============start here to get new stock data=======================

    # for ticker in tickers:
    #     print ticker
    #     time.sleep(.02)
    #     # print ticker
    #     df = web.DataReader(ticker, 'iex', start, end)
    #     df = df.reset_index(level='date')
    #     # print df.head()
    #     ticker_data.append_change_column(df, ticker)

    #     i = i + 50

    # # remove the rows that contain any 0's or NA

    # ticker_data.main_df.to_csv('before_NA_drop_stock_data_slope_sumNoNA' +
    #                            str(start) + '--' + str(end) + '.csv')
    # # ticker_data.drop_row_with_zeros()
    # ticker_data.drop_row_with_NA()

    # ticker_data.main_df.to_pickle(
    #     'stock_data/df_without_NA_' + str(start) + '--' + str(end) + '.pkl')

    # NOTE ============end================================================

    ticker_data.main_df = pd.read_pickle('stock_data/df_without_NA_' +
                                         str(start) + '--' + str(end) + '.pkl')

    # add the slope sum values to the dataframe
    # ticker_data.main_df = sample_slopes.create_slope_sum(ticker_data.main_df)

    ticker_data.main_df = sample_slopes.create_slope_sum_market(
        ticker_data.main_df)

    # write the whole datarame to a csv if you want to
    ticker_data.main_df.to_csv('stock_data_slope_sumNoNA' + str(start) + '--' +
                               str(end) + '.csv')

    # get the names of all the column titles
    columns = list(ticker_data.main_df)

    # get the names of the columns that have a slope_sum
    columns_with_sample_slopes = sample_slopes.get_columns_with_slope_sum(
        columns)

    # set up the ML package to hold the features and target values
    sv = support_vector.Support_Vector([], [])

    for column in columns_with_sample_slopes:

        y_values = sample_slopes.generate_target_values(
            ticker_data.main_df, batch_size,
            column.replace('slope_sum', 'CLS'), look_ahead)
        # keeps adding new target values to varable
        sv.Y = sv.Y + y_values[0]

        # create_batch_of_slopes(df, batch_count, cut_length)
        # y_values[1] bec thats used to tell create batch_of_slopes where to
        # stop

        x_values = sample_slopes.create_batch_of_slopes(
            ticker_data.main_df, column, batch_size, y_values[1])

        # x_values = sample_slopes.create_batch_of_slopes_moving_av(
        #     ticker_data.main_df, column, batch_size,   y_values[1], 15)

        # keeps adding new feature values to varable
        sv.X = sv.X + x_values

    write_feature_and_targets(sv.X, sv.Y)

    print(sv.Y, 'Yvalues')
    print(sv.X[-1], ' Xvalues ')
    # print sv.X, 'Xvalues'
    print('training the model...')

    sv.train()
Ejemplo n.º 10
0
def test_plot_stock():
    """
    Makes sure we can just plot a stock
    """
    batch_size = 18
    look_ahead = 2
    ticker = 'ADBE'
    main_df = pd.read_pickle(settings.settings_dict['stock_data_path'])
    main_df = sample_slopes.create_slope_sum_market(main_df)

    Back_Test = back_test.BackTest(main_df,
                                   settings.settings_dict['model_path'])

    y_values = sample_slopes.generate_target_values(main_df, batch_size,
                                                    ticker + 'CLS', look_ahead)

    x_values = sample_slopes.create_batch_of_slopes(main_df, ticker + 'CLS',
                                                    batch_size, y_values[1])

    array_of_batches = Back_Test.create_batch_of_slopes(
        main_df, ticker + 'slope_sum', batch_size, y_values[1])

    Back_Test.append_list_of_buy_sells(array_of_batches, ticker + "slope_sum")

    algorithm_return = Back_Test.take_bid_stream_calculate_profit(
        ticker + "bid_stream", batch_size, look_ahead, for_graph=True)

    array_of_bid_stream = Back_Test.main_df[ticker +
                                            'bid_stream'].tolist()[batch_size +
                                                                   look_ahead -
                                                                   1:]
    index_bid_stream = range(0, len(array_of_bid_stream))

    array_of_bid_stream = np.array(array_of_bid_stream) * 5

    runningTotal = []
    total = 0
    for n in algorithm_return:
        total += n
        runningTotal.append(total)

    # list_of_bids = Back_Test.array_of_profits
    # shift the graph to the left to account for the initial days there there
    # inst enough info for
    index = range(0, len(runningTotal))

    index_stock = range(
        0, len(main_df[ticker + 'CLS'].tolist()[batch_size + look_ahead - 1:]))

    plt.plot(index_stock,
             main_df[ticker + 'CLS'].tolist()[batch_size + look_ahead - 1:],
             'r',
             label=ticker + ' Close')

    plt.plot(index, runningTotal, 'g', label='Algorithm Profits')

    plt.title(ticker + ' Profit')

    plt.plot(index_bid_stream, array_of_bid_stream, 'b', label='Bid Stream')

    print len(main_df[ticker + 'CLS'].tolist()), 'length of the close valeus'
    print len(algorithm_return), 'algo proffits'
    print len(runningTotal), 'runnign total'
    print len(array_of_bid_stream), 'bid stream len'
    print array_of_bid_stream[:50], 'bid stream'

    helper_turn_data_into_csv(
        main_df[ticker + 'CLS'].tolist()[:len(runningTotal)], runningTotal,
        array_of_bid_stream[:len(runningTotal)])

    plt.legend(loc='best')
    plt.show()
Ejemplo n.º 11
0
def test_generate_target_values_longer():
    """
    used to tests really long CLS lengths
    """
    data = {
        'col2CLS': [
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8,
            6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5,
            5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6,
            7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6,
            4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3,
            3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8, 6, 5, 5, 6, 7, 6, 4, 3, 3, 8
        ],
    }
    stock_data = pd.DataFrame(data=data)

    sample_slopes.generate_target_values(stock_data, 18, 'col2CLS', 2)
Ejemplo n.º 12
0
def test_on_array_of_tickers_profit():
    """
    This test is used to try out the returns calculator on the stock market data
    """
    tickers = [
        "GOOG", "FB", "INTC", 'TSM', "CSCO", "ORCL", "NVDA", "SAP", "IBM",
        "ADBE", "TXN", "AVGO", "CRM", "QCOM", "MU", "BIDU", "ADP", "VMW",
        "ATVI", "AMAT", "INTU", "CTSH", "EA", "NXPI", "INFY"
    ]

    # tickers = ["GOOG", "FB", "INTC", 'TSM', "CSCO"]

    main_df = pd.read_pickle(settings.settings_dict['stock_data_path'])
    main_df = sample_slopes.create_slope_sum_market(main_df)

    Back_Test = back_test.BackTest(main_df,
                                   settings.settings_dict['model_path'])

    with open('files/testing_files/return_output.csv', 'w') as f:
        mean_array = []
        std_array = []
        returns_difference_array = []
        for ticker in tickers:

            slope_sums = main_df[ticker + "slope_sum"]

            mean = np.mean(main_df[ticker + "slope_sum"])
            std = np.std(main_df[ticker + "slope_sum"])

            y_values = sample_slopes.generate_target_values(
                main_df, 18, ticker + "CLS", 2)

            x_values = sample_slopes.create_batch_of_slopes(
                main_df, ticker + 'CLS', 18, y_values[1])

            array_of_batches = Back_Test.create_batch_of_slopes(
                main_df, ticker + 'slope_sum', 18, y_values[1])

            Back_Test.append_list_of_buy_sells(array_of_batches,
                                               ticker + "slope_sum")

            algorithm_profit = sum(
                Back_Test.take_bid_stream_calculate_profit(
                    ticker + "bid_stream", 18, 2))
            print Back_Test.take_bid_stream_calculate_profit(
                ticker + "bid_stream", 18, 2)
            log_return = sum(
                Back_Test.test_calculate_holding_log_return(ticker + 'CLS'))
            holding_profit = Back_Test.calculate_holding_profit(
                ticker + "CLS", 18, 2)

            print "algorithm ", algorithm_profit
            print "log return ", log_return, ' %'
            print "percent change", holding_profit,

            mean_array.append(mean)
            std_array.append(std)
            returns_difference_array.append(algorithm_profit - holding_profit)

            f.write(ticker + ',' + str(algorithm_profit) + ',' +
                    str(log_return) + ',' + str(holding_profit) + ',' +
                    str(mean) + ',' + str(std) + '\n')

        data = {
            'mean': mean_array,
            'std': std_array,
            'returns_diff': returns_difference_array
        }
        meaningfull_stats = pd.DataFrame(data=data)

        meaningfull_stats.to_pickle('files/meaningfull_stats.pkl')