def prepare_data():

    openp = data_original[:, 1].tolist()[0:]
    highp = data_original[:, 2].tolist()[0:]
    lowp = data_original[:, 3].tolist()[0:]
    closep = data_original[:, 4].tolist()[0:]
    volumep = data_original[:, 5].tolist()[0:]

    #open = data_original['Open'].rolling(21).mean()
    #high = data_original['High'].rolling(21).mean()
    #low = data_original['low'].rolling(21).mean()
    close = pd.DataFrame(closep).rolling(21, min_periods=0).mean()

    close_ema = pd.DataFrame(closep).ewm(span=21,min_periods=21-1 ,adjust=False).mean()
    print(close)
    print("ema: ", close_ema)
    #macdk= ta.MACD(np.array(closep))
    #print("macd ",macdk)

    x_i = np.column_stack((openp, highp, lowp, closep, volumep,close))
    print("len", (len(x_i)))
    # print("X_i",x_i)
    y_i = closep
    x, y = np.array(x_i), np.array(y_i)
    tr_date, ts_date, X_train, X_test, Y_train, Y_test = create_Xt_Yt(timestamp, x, y)

    return tr_date, ts_date, X_train, X_test, Y_train, Y_test
    print("fun prepare_Data ended!!! ")
示例#2
0
def data_sets(labels, volumep1, p_sets, y_i, timestamp):
    for i in range(1, len(p_sets), 1):
        ps = p_sets[i]
        label = labels[i]
        x_i = np.column_stack(ps)
        x_i, y_i = np.array(x_i), np.array(y_i)
        #print('ps:  ' + str(i) + "", ps)
        print("len of p: " + str(i) + ": ", len(ps))
        #print('x_ ' + str(i) + ":  ", x_i)
        tr_date, ts_date, X_train, X_test, Y_train, Y_test = create_Xt_Yt(
            timestamp, x_i, y_i)
        prepare_model(i, label, volumep1, tr_date, ts_date, X_train, X_test,
                      Y_train, Y_test)
示例#3
0
def prepare_data(data_original, timestamp):
    openp = data_original[:, 1].tolist()[0:]
    highp = data_original[:, 2].tolist()[0:]
    lowp = data_original[:, 3].tolist()[0:]
    closep = data_original[:, 4].tolist()[0:]
    volumep = data_original[:, 5].tolist()[0:]
    x_i = np.column_stack((openp, highp, lowp, closep, volumep))
    print("len", (len(x_i)))
    # print("X_i",x_i)
    y_i = closep
    x, y = np.array(x_i), np.array(y_i)

    tr_date, ts_date, X_train, X_test, Y_train, Y_test = create_Xt_Yt(
        timestamp, x, y)
    return tr_date, ts_date, X_train, X_test, Y_train, Y_test
示例#4
0
def prepare_data(data_original, timestamp):
    openp = data_original[:, 1].tolist()[0:]
    highp = data_original[:, 2].tolist()[0:]
    lowp = data_original[:, 3].tolist()[0:]
    closep = data_original[:, 4].tolist()[0:]
    volumep = data_original[:, 5].tolist()[0:]
    x, y = [], []

    x_i = np.column_stack((openp, highp, lowp, closep, volumep))
    print("len", (len(x_i)))
    # print("X_i",x_i)
    y_i = volumep
    # print("closeP: ",pd.DataFrame(y_i))
    x, y = np.array(x_i), np.array(y_i)
    # print("X",X)
    tr_date, ts_date, X_train, X_test, Y_train, Y_test = create_Xt_Yt(
        timestamp, x, y)
    return tr_date, ts_date, X_train, X_test, Y_train, Y_test
    print("fun prepare_Data ended!!! ")
示例#5
0
def prepare_data(data_original, timestamp):
    '''
    openp = data_original[:, 1].tolist()[0:]
    highp = data_original[:, 2].tolist()[0:]
    lowp = data_original[:, 3].tolist()[0:]
    closep = data_original[:, 4].tolist()[0:]
    volumep = data_original[:, 5].tolist()[0:]
    '''
    openp = data_original.ix[:, 'Open'].tolist()[0:]
    highp = data_original.ix[:, 'High'].tolist()[0:]
    lowp = data_original.ix[:, 'Low'].tolist()[0:]
    closep = data_original.ix[:, 'Close'].tolist()[0:]
    volumep = data_original.ix[:, 'Volume_(BTC)'].tolist()[0:]
    print(openp)
    #volumecp = data_original.ix[:, 'Volume_(Currency)'].tolist()[1:]

    x, y = [], []

    X, Y = [], []
    for i in range(0, len(data_original), STEP):
        try:
            o = openp[i:i + window]
            h = highp[i:i + window]
            l = lowp[i:i + window]
            c = closep[i:i + window]
            v = volumep[i:i + window]
            #vc = volumecp[i:i + window]
            #volat = volatility[i:i + window]
            print("o ", o)

            o = (np.array(o) - np.mean(o)) / np.std(o)
            print("mean o ", o)
            h = (np.array(h) - np.mean(h)) / np.std(h)
            l = (np.array(l) - np.mean(l)) / np.std(l)
            c = (np.array(c) - np.mean(c)) / np.std(c)
            v = (np.array(v) - np.mean(v)) / np.std(v)

            #vc = (np.array(vc) - np.mean(vc)) / np.std(vc)
            #volat = (np.array(volat) - np.mean(volat)) / np.std(volat)

            x_i = np.column_stack((o, h, l, c, v))
            x_i = x_i.flatten()

            y_i = (closep[i + window + FORECAST] -
                   closep[i + window]) / closep[i + window]

            if np.isnan(x_i).any():
                continue

        except Exception as e:
            break

        x.append(x_i)
        y.append(y_i)
    '''
    x_i = np.column_stack((openp, highp, lowp, closep, volumep))
    print("len", (len(x_i)))
    # print("X_i",x_i)
    y_i = closep
    # print("closeP: ",pd.DataFrame(y_i))
    '''

    x, y = np.array(x), np.array(y)
    # print("X",X)
    print(len(x), len(y))

    tr_date, ts_date, X_train, X_test, Y_train, Y_test = create_Xt_Yt(
        timestamp, x, y)
    return tr_date, ts_date, X_train, X_test, Y_train, Y_test
    print("fun prepare_Data ended!!! ")