Esempio n. 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
Esempio n. 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
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