Пример #1
0
def predictFuture(m1,m2,old_pred,writeToFile=False):
    actual,latest_p = util.getCurrentData(label=True)
    actual = np.array(util.reduceCurrent(actual)).reshape(1,12)
    pred = util.augmentValue(net.predict(actual)[0],m1,m2)
    pred = float(int(pred[0]*100)/100)
    if writeToFile:
        f = open("results","a")
        f.write("[{}] Actual:{}$ Last Prediction:{}$ Next 9m:{}$\n".format(time.strftime("%H:%M:%S"),latest_p,old_pred,pred))
        f.close()

    print("[{}] Actual:{}$ Last Prediction:{}$ Next 9m:{}$".format(time.strftime("%H:%M:%S"),latest_p,old_pred,pred))
    return latest_p,pred
Пример #2
0
def predictFuture(m1,m2,old_pred,writeToFile=False):
    actual,latest_p = util.getCurrentData(label=True)
    actual = np.array(util.reduceCurrent(actual)).reshape(1,12)
    pred = util.augmentValue(net.predict(actual)[0],m1,m2)
    pred = float(int(pred[0]*100)/100)
    cex = util.getCEXData()
    slope,nrmse = predict.getslope(False)
    if writeToFile:
        f = open("results","a")
        f.write("[{}] Actual:{}$ Last Prediction:{}$ Next {}sec:{}$\n".format(time.strftime("%H:%M:%S"),latest_p,old_pred,wait_time,pred))
        f.close()

    c = conn.cursor()
    c.execute("INSERT INTO predict(actual,last,target,cex_ask,slope,nrmse) VALUES (?,?,?,?,?,?)",(latest_p,old_pred,pred,cex["ask"],slope,nrmse))
    conn.commit()
    print("[{}] Actual:{}$ Last Prediction:{}$ Next {}sec:{}$ Slope:{}$ NRMSE:{}$\n".format(time.strftime("%H:%M:%S"),latest_p,old_pred,wait_time,pred,slope,nrmse))
    return latest_p,pred
Пример #3
0
def predictFuture(m1,
                  m2,
                  old_pred,
                  window_data,
                  prev_closep,
                  writeToFile=False):
    actual, latest_p, ctime = util.getCurrentData(label=True)
    if net_type == 'RNN':
        actual = np.array(util.reduceCurrent(actual)).reshape(1, 12)
        pred = util.augmentValue(net.predict(actual)[0], m1, m2)
        pred = float(int(pred[0] * 100) / 100)
        if writeToFile:
            f = open("results", "a")
            f.write("[{}] Actual:{}$ Last Prediction:{}$ Next 9m:{}$\n".format(
                time.strftime("%H:%M:%S"), latest_p, old_pred, pred))
            f.close()

        print("[{}] Actual:{}$ Last Prediction:{}$ Next 9m:{}$".format(
            time.strftime("%H:%M:%S"), latest_p, old_pred, pred))
        return latest_p, pred, 0, 0, ctime
    else:
        for i in xrange(1, len(window_data)):
            window_data[i - 1][:] = window_data[i][:]
        window_data[len(window_data) - 1][:] = actual
        actual = np.array(window_data).reshape(1, window, 12)
        pred = (net.predict(actual)[0])
        real = util.convert_close_to_label(prev_closep, latest_p)
        if writeToFile:
            f = open("results", "a")
            f.write(
                "[{}] Actual:{}$, Last actual value {}, Last Prediction:{}$ Next 9m:{}\n"
                .format(time.strftime("%H:%M:%S"), latest_p, prev_closep,
                        old_pred, np.argmax(pred)))
            f.close()

        print(
            "[{}] Actual:{}$, Last actual value {},  Last Prediction:{}$ Next 9m:{}"
            .format(time.strftime("%H:%M:%S"), latest_p, prev_closep, old_pred,
                    label[np.argmax(pred)]))
        return np.argmax(real), np.argmax(pred), window_data, latest_p, ctime
Пример #4
0
    data = util.reduceMatRows(data)
    labels,m1,m2 =util.reduceVector(labels,getVal=True)
    print("{} chunk loaded!\n".format(len(labels)),end="")

    if args.run is not None:
        #Loading weights
        w_name = args.model
        net.load_weights(w_name)
        epochs = "run"
        print("Starting main loop...")
        hip = 0
        reals,preds = [],[]

        for i in range(len(data)-40,len(data)):
            x = np.array(data[i]).reshape(1,12)
            predicted = util.augmentValue(net.predict(x)[0],m1,m2)[0]
            real = util.augmentValue(labels[i],m1,m2)
            preds.append(predicted)
            reals.append(real)

        while True:
            try:
                real,hip = predictFuture(m1,m2,hip,writeToFile=True)
                reals.append(real)
                preds.append(hip)
                time.sleep(wait_time)
            except KeyboardInterrupt:
                ### PLOTTING
                chart(reals,preds,show=False)
                print("Chart saved!")
                s = input("Type yes to close the program: ")