aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-09-02 13:38:33 +0000
committerbloodstalker <thabogre@gmail.com>2018-09-02 13:38:33 +0000
commit66afd62322e92666245ca7ceb8b070c4f6298a2c (patch)
treed442644ae71f5490e1ba1831ac1c2376c7c1ec4a
parentupdate (diff)
downloadseer-66afd62322e92666245ca7ceb8b070c4f6298a2c.tar.gz
seer-66afd62322e92666245ca7ceb8b070c4f6298a2c.zip
update
-rw-r--r--lstm-models/ethereum_model_randseed_775.h5bin0 -> 49504 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_776.h5bin0 -> 49536 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_777.h5bin0 -> 49536 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_778.h5bin0 -> 49536 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_779.h5bin0 -> 49536 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_780.h5bin0 -> 49536 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_781.h5bin0 -> 49536 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_782.h5bin0 -> 49536 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_783.h5bin0 -> 49552 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_784.h5bin0 -> 49552 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_785.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_786.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_787.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_788.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_789.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_790.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_791.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_792.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_793.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_794.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_795.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_796.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_797.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_798.h5bin0 -> 49568 bytes
-rw-r--r--lstm-models/ethereum_model_randseed_799.h5bin0 -> 49568 bytes
-rwxr-xr-xlstm.py23
-rwxr-xr-xseer.py5
-rwxr-xr-xtfann.py157
28 files changed, 177 insertions, 8 deletions
diff --git a/lstm-models/ethereum_model_randseed_775.h5 b/lstm-models/ethereum_model_randseed_775.h5
new file mode 100644
index 0000000..27fc878
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_775.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_776.h5 b/lstm-models/ethereum_model_randseed_776.h5
new file mode 100644
index 0000000..e45229a
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_776.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_777.h5 b/lstm-models/ethereum_model_randseed_777.h5
new file mode 100644
index 0000000..e341f72
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_777.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_778.h5 b/lstm-models/ethereum_model_randseed_778.h5
new file mode 100644
index 0000000..a53d9bf
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_778.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_779.h5 b/lstm-models/ethereum_model_randseed_779.h5
new file mode 100644
index 0000000..01a57f4
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_779.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_780.h5 b/lstm-models/ethereum_model_randseed_780.h5
new file mode 100644
index 0000000..5882283
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_780.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_781.h5 b/lstm-models/ethereum_model_randseed_781.h5
new file mode 100644
index 0000000..4bda2c7
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_781.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_782.h5 b/lstm-models/ethereum_model_randseed_782.h5
new file mode 100644
index 0000000..d6d2177
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_782.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_783.h5 b/lstm-models/ethereum_model_randseed_783.h5
new file mode 100644
index 0000000..f52f6f9
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_783.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_784.h5 b/lstm-models/ethereum_model_randseed_784.h5
new file mode 100644
index 0000000..6d9b7a5
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_784.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_785.h5 b/lstm-models/ethereum_model_randseed_785.h5
new file mode 100644
index 0000000..370cb02
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_785.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_786.h5 b/lstm-models/ethereum_model_randseed_786.h5
new file mode 100644
index 0000000..43153a1
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_786.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_787.h5 b/lstm-models/ethereum_model_randseed_787.h5
new file mode 100644
index 0000000..2bb8ddc
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_787.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_788.h5 b/lstm-models/ethereum_model_randseed_788.h5
new file mode 100644
index 0000000..74a5a8c
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_788.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_789.h5 b/lstm-models/ethereum_model_randseed_789.h5
new file mode 100644
index 0000000..4af9d00
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_789.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_790.h5 b/lstm-models/ethereum_model_randseed_790.h5
new file mode 100644
index 0000000..45ba97b
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_790.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_791.h5 b/lstm-models/ethereum_model_randseed_791.h5
new file mode 100644
index 0000000..5737de7
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_791.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_792.h5 b/lstm-models/ethereum_model_randseed_792.h5
new file mode 100644
index 0000000..9f87916
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_792.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_793.h5 b/lstm-models/ethereum_model_randseed_793.h5
new file mode 100644
index 0000000..4912524
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_793.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_794.h5 b/lstm-models/ethereum_model_randseed_794.h5
new file mode 100644
index 0000000..4f73257
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_794.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_795.h5 b/lstm-models/ethereum_model_randseed_795.h5
new file mode 100644
index 0000000..982127a
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_795.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_796.h5 b/lstm-models/ethereum_model_randseed_796.h5
new file mode 100644
index 0000000..7205a00
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_796.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_797.h5 b/lstm-models/ethereum_model_randseed_797.h5
new file mode 100644
index 0000000..3c0114d
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_797.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_798.h5 b/lstm-models/ethereum_model_randseed_798.h5
new file mode 100644
index 0000000..59d9a13
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_798.h5
Binary files differ
diff --git a/lstm-models/ethereum_model_randseed_799.h5 b/lstm-models/ethereum_model_randseed_799.h5
new file mode 100644
index 0000000..bdc74fa
--- /dev/null
+++ b/lstm-models/ethereum_model_randseed_799.h5
Binary files differ
diff --git a/lstm.py b/lstm.py
index 0860628..f27b892 100755
--- a/lstm.py
+++ b/lstm.py
@@ -17,6 +17,7 @@ from keras.models import Sequential
from keras.layers import Activation, Dense
from keras.layers import LSTM
from keras.layers import Dropout
+from keras.models import load_model
window_len = 10
split_date = "2017-06-01"
@@ -75,7 +76,7 @@ def get_sets(crypto, model_data):
LSTM_test_inputs = [np.array(LSTM_test_inputs) for LSTM_test_inputs in LSTM_test_inputs]
LSTM_test_inputs = np.array(LSTM_test_inputs)
- return LSTM_training_inputs, LSTM_test_inputs, training_set
+ return LSTM_training_inputs, LSTM_test_inputs, training_set, test_set
def build_model(inputs, output_size, neurons, activ_func="linear", dropout=0.25, loss="mae", optimizer="adam"):
model = Sequential()
@@ -89,7 +90,7 @@ def build_model(inputs, output_size, neurons, activ_func="linear", dropout=0.25,
def lstm_type_1(crypto, crypto_short):
model_data = getData_CMC(crypto, crypto_short)
np.random.seed(202)
- training_inputs, test_inputs, training_set = get_sets(crypto, model_data)
+ training_inputs, test_inputs, training_set, test_set = get_sets(crypto, model_data)
model = build_model(training_inputs, output_size=1, neurons=20)
training_outputs = (training_set['Close'][window_len:].values/training_set['Close'][:-window_len].values)-1
history = model.fit(training_inputs, training_outputs, epochs=50, batch_size=1, verbose=2, shuffle=True)
@@ -97,7 +98,7 @@ def lstm_type_1(crypto, crypto_short):
def lstm_type_2(crypto, crypto_short, pred_range, neuron_count):
model_data = getData_CMC(crypto, crypto_short)
np.random.seed(202)
- training_inputs, test_inputs, training_set = get_sets(crypto, model_data)
+ training_inputs, test_inputs, training_set, test_set = get_sets(crypto, model_data)
model = build_model(training_inputs, output_size=pred_range, neurons=neuron_count)
training_outputs = (training_set['Close'][window_len:].values/training_set['Close'][:-window_len].values)-1
training_outputs = []
@@ -109,7 +110,7 @@ def lstm_type_2(crypto, crypto_short, pred_range, neuron_count):
def lstm_type_3(crypto, crypto_short, pred_range, neuron_count):
model_data = getData_CMC(crypto, crypto_short)
np.random.seed(202)
- training_inputs, test_inputs, training_set = get_sets(crypto, model_data)
+ training_inputs, test_inputs, training_set, test_set = get_sets(crypto, model_data)
model = build_model(training_inputs, output_size=1, neurons=neuron_count)
training_outputs = (training_set['Close'][window_len:].values/training_set['Close'][:-window_len].values)-1
training_outputs = []
@@ -118,7 +119,16 @@ def lstm_type_3(crypto, crypto_short, pred_range, neuron_count):
np.random.seed(rand_seed)
temp_model = build_model(training_inputs, output_size=1, neurons=neuron_count)
temp_model.fit(training_inputs, (training_set['Close'][window_len:].values/training_set['Close'][:-window_len].values)-1, epochs=50, batch_size=1, verbose=0, shuffle=True)
- temp_model.save(crypto + '_model_randseed_%d.h5'%rand_seed)
+ temp_model.save("./lstm-models/" + crypto + '_model_randseed_%d.h5'%rand_seed)
+
+def load_models(crypto, crypto_short):
+ preds = []
+ model_data = getData_CMC(crypto, crypto_short)
+ np.random.seed(202)
+ training_inputs, test_inputs, training_set, test_set = get_sets(crypto, model_data)
+ for rand_seed in range(775,800):
+ temp_model = load_model("./lstm-models/" + crypto + '_model_randseed_%d.h5'%rand_seed)
+ preds.append(np.mean(abs(np.transpose(temp_model.predict(test_inputs))-(test_set['Close'].values[window_len:]/test_set['Close'].values[:-window_len]-1))))
# write code here
def premain(argparser):
@@ -126,7 +136,8 @@ def premain(argparser):
#here
#lstm_type_1("ethereum", "ether")
#lstm_type_2("ethereum", "ether", 5, 20)
- lstm_type_3("ethereum", "ether", 5, 20)
+ #lstm_type_3("ethereum", "ether", 5, 20)
+ load_models("ethereum", "eth")
def main():
argparser = Argparser()
diff --git a/seer.py b/seer.py
index e95a6d8..006eaf3 100755
--- a/seer.py
+++ b/seer.py
@@ -6,8 +6,9 @@ import code
import readline
import signal
import sys
-from ltsm import lstm_type_1, lstm_type_2, lstm_type_3
-from cnn import marrionette_type_1
+from lstm import lstm_type_1, lstm_type_2, lstm_type_3
+from marionette import marrionette_type_1
+from tfann import tfann_type_1
def SigHandler_SIGINT(signum, frame):
print()
diff --git a/tfann.py b/tfann.py
new file mode 100755
index 0000000..326182c
--- /dev/null
+++ b/tfann.py
@@ -0,0 +1,157 @@
+#!/usr/bin/python3
+# _*_ coding=utf-8 _*_
+# original source-https://nicholastsmith.wordpress.com/2017/11/13/cryptocurrency-price-prediction-using-deep-learning-in-tensorflow/
+
+import argparse
+import code
+import readline
+import signal
+import sys
+from TFANN import ANNR
+import numpy as np
+import os
+import pandas as pd
+import urllib.request
+import matplotlib.pyplot as mpl
+
+def SigHandler_SIGINT(signum, frame):
+ print()
+ sys.exit(0)
+
+class Argparser(object):
+ def __init__(self):
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--string", type=str, help="string")
+ parser.add_argument("--bool", action="store_true", help="bool", default=False)
+ parser.add_argument("--dbg", action="store_true", help="debug", default=False)
+ self.args = parser.parse_args()
+
+def GetAPIUrl(cur, sts = 1420070400):
+ return 'https://poloniex.com/public?command=returnChartData&currencyPair=USDT_{:s}&start={:d}&end=9999999999&period=7200'.format(cur, sts)
+
+def GetCurDF(cur, fp):
+ openUrl = urllib.request.urlopen(GetAPIUrl(cur))
+ r = openUrl.read()
+ openUrl.close()
+ df = pd.read_json(r.decode())
+ df['date'] = df['date'].astype(np.int64) // 1000000000
+ return df
+
+class PastSampler:
+ def __init__(self, N, K):
+ self.K = K
+ self.N = N
+
+ def transform(self, A, Y = None):
+ M = self.N + self.K #Number of samples per row (sample + target)
+ #Matrix of sample indices like: {{1, 2..., M}, {2, 3, ..., M + 1}}
+ I = np.arange(M) + np.arange(A.shape[0] - M + 1).reshape(-1, 1)
+ B = A[I].reshape(-1, M * A.shape[1], *A.shape[2:])
+ ci = self.N * A.shape[1] #Number of features per sample
+ return B[:, :ci], B[:, ci:] #Sample matrix, Target matrix
+
+def tfann_type_1():
+ #%%Path to store cached currency data
+ datPath = 'CurDat/'
+ if not os.path.exists(datPath):
+ os.mkdir(datPath)
+ #Different cryptocurrency types
+ cl = ['BTC', 'LTC', 'ETH', 'XMR']
+ #Columns of price data to use
+ CN = ['close', 'high', 'low', 'open', 'volume']
+ #Store data frames for each of above types
+ D = []
+ for ci in cl:
+ dfp = os.path.join(datPath, ci + '.csv')
+ try:
+ df = pd.read_csv(dfp, sep = ',')
+ except FileNotFoundError:
+ df = GetCurDF(ci, dfp)
+ D.append(df)
+ #%%Only keep range of data that is common to all currency types
+ cr = min(Di.shape[0] for Di in D)
+ for i in range(len(cl)):
+ D[i] = D[i][(D[i].shape[0] - cr):]
+ #%%Features are channels
+ C = np.hstack((Di[CN] for Di in D))[:, None, :]
+ HP = 16 #Holdout period
+ A = C[0:-HP]
+ SV = A.mean(axis = 0) #Scale vector
+ C /= SV #Basic scaling of data
+ #%%Make samples of temporal sequences of pricing data (channel)
+ NPS, NFS = 256, 16 #Number of past and future samples
+ ps = PastSampler(NPS, NFS)
+ B, Y = ps.transform(A)
+ #%%Architecture of the neural network
+ NC = B.shape[2]
+ #2 1-D conv layers with relu followed by 1-d conv output layer
+ ns = [('C1d', [8, NC, NC * 2], 4), ('AF', 'relu'),
+ ('C1d', [8, NC * 2, NC * 2], 2), ('AF', 'relu'),
+ ('C1d', [8, NC * 2, NC], 2)]
+ #Create the neural network in TensorFlow
+ cnnr = ANNR(B[0].shape, ns, batchSize = 32, learnRate = 2e-5,
+ maxIter = 64, reg = 1e-5, tol = 1e-2, verbose = True)
+ cnnr.fit(B, Y)
+ PTS = [] #Predicted time sequences
+ P, YH = B[[-1]], Y[[-1]] #Most recent time sequence
+ for i in range(HP // NFS): #Repeat prediction
+ P = np.concatenate([P[:, NFS:], YH], axis = 1)
+ YH = cnnr.predict(P)
+ PTS.append(YH)
+ PTS = np.hstack(PTS).transpose((1, 0, 2))
+ A = np.vstack([A, PTS]) #Combine predictions with original data
+ A = np.squeeze(A) * SV #Remove unittime dimension and rescale
+ C = np.squeeze(C) * SV
+ nt = 4
+ PF = cnnr.PredictFull(B[:nt])
+ for i in range(nt):
+ fig, ax = mpl.subplots(1, 4, figsize = (16 / 1.24, 10 / 1.25))
+ ax[0].plot(PF[0][i])
+ ax[0].set_title('Input')
+ ax[1].plot(PF[2][i])
+ ax[1].set_title('Layer 1')
+ ax[2].plot(PF[4][i])
+ ax[2].set_title('Layer 2')
+ ax[3].plot(PF[5][i])
+ ax[3].set_title('Output')
+ fig.text(0.5, 0.06, 'Time', ha='center')
+ fig.text(0.06, 0.5, 'Activation', va='center', rotation='vertical')
+ mpl.show()
+ CI = list(range(C.shape[0]))
+ AI = list(range(C.shape[0] + PTS.shape[0] - HP))
+ NDP = PTS.shape[0] #Number of days predicted
+ for i, cli in enumerate(cl):
+ fig, ax = mpl.subplots(figsize = (16 / 1.5, 10 / 1.5))
+ hind = i * len(CN) + CN.index('high')
+ ax.plot(CI[-4 * HP:], C[-4 * HP:, hind], label = 'Actual')
+ ax.plot(AI[-(NDP + 1):], A[-(NDP + 1):, hind], '--', label = 'Prediction')
+ ax.legend(loc = 'upper left')
+ ax.set_title(cli + ' (High)')
+ ax.set_ylabel('USD')
+ ax.set_xlabel('Time')
+ ax.axes.xaxis.set_ticklabels([])
+ mpl.show()
+
+# write code here
+def premain(argparser):
+ signal.signal(signal.SIGINT, SigHandler_SIGINT)
+ #here
+ tfann_type_1()
+
+def main():
+ argparser = Argparser()
+ if argparser.args.dbg:
+ try:
+ premain(argparser)
+ except Exception as e:
+ print(e.__doc__)
+ if e.message: print(e.message)
+ variables = globals().copy()
+ variables.update(locals())
+ shell = code.InteractiveConsole(variables)
+ shell.interact(banner="DEBUG REPL")
+ else:
+ premain(argparser)
+
+if __name__ == "__main__":
+ main()