diff --git a/__pycache__/functions.cpython-310.pyc b/__pycache__/functions.cpython-310.pyc new file mode 100644 index 0000000..196fa8e Binary files /dev/null and b/__pycache__/functions.cpython-310.pyc differ diff --git a/agent/__pycache__/__init__.cpython-310.pyc b/agent/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..62b50ce Binary files /dev/null and b/agent/__pycache__/__init__.cpython-310.pyc differ diff --git a/agent/__pycache__/agent.cpython-310.pyc b/agent/__pycache__/agent.cpython-310.pyc new file mode 100644 index 0000000..28bcca5 Binary files /dev/null and b/agent/__pycache__/agent.cpython-310.pyc differ diff --git a/agent/agent.py b/agent/agent.py index 07e163b..b8c6364 100644 --- a/agent/agent.py +++ b/agent/agent.py @@ -44,7 +44,7 @@ def act(self, state): def expReplay(self, batch_size): mini_batch = [] l = len(self.memory) - for i in xrange(l - batch_size + 1, l): + for i in range(l - batch_size + 1, l): mini_batch.append(self.memory[i]) for state, action, reward, next_state, done in mini_batch: diff --git a/evaluate.py b/evaluate.py index 0055e9d..dc980ae 100644 --- a/evaluate.py +++ b/evaluate.py @@ -6,7 +6,7 @@ import sys if len(sys.argv) != 3: - print "Usage: python evaluate.py [stock] [model]" + print ("Usage: python evaluate.py [stock] [model]") exit() stock_name, model_name = sys.argv[1], sys.argv[2] @@ -22,7 +22,7 @@ total_profit = 0 agent.inventory = [] -for t in xrange(l): +for t in range(l): action = agent.act(state) # sit @@ -31,19 +31,19 @@ if action == 1: # buy agent.inventory.append(data[t]) - print "Buy: " + formatPrice(data[t]) + print ("Buy: " + formatPrice(data[t])) elif action == 2 and len(agent.inventory) > 0: # sell bought_price = agent.inventory.pop(0) reward = max(data[t] - bought_price, 0) total_profit += data[t] - bought_price - print "Sell: " + formatPrice(data[t]) + " | Profit: " + formatPrice(data[t] - bought_price) + print ("Sell: " + formatPrice(data[t]) + " | Profit: " + formatPrice(data[t] - bought_price)) done = True if t == l - 1 else False agent.memory.append((state, action, reward, next_state, done)) state = next_state if done: - print "--------------------------------" - print stock_name + " Total Profit: " + formatPrice(total_profit) - print "--------------------------------" + print ("--------------------------------") + print (stock_name + " Total Profit: " + formatPrice(total_profit)) + print ("--------------------------------") diff --git a/functions.py b/functions.py index 5129e0c..f8d216e 100644 --- a/functions.py +++ b/functions.py @@ -24,7 +24,7 @@ def getState(data, t, n): d = t - n + 1 block = data[d:t + 1] if d >= 0 else -d * [data[0]] + data[0:t + 1] # pad with t0 res = [] - for i in xrange(n - 1): + for i in range(n - 1): res.append(sigmoid(block[i + 1] - block[i])) return np.array([res]) diff --git a/train.py b/train.py index c4ba8ed..bd5775f 100644 --- a/train.py +++ b/train.py @@ -3,24 +3,24 @@ import sys if len(sys.argv) != 4: - print "Usage: python train.py [stock] [window] [episodes]" + print ("Usage: python train.py [stock] [window] [episodes]") exit() stock_name, window_size, episode_count = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]) agent = Agent(window_size) -data = getStockDataVec(stock_name) +data = cha(stock_name) l = len(data) - 1 batch_size = 32 -for e in xrange(episode_count + 1): - print "Episode " + str(e) + "/" + str(episode_count) +for e in range(episode_count + 1): + print ("Episode " + str(e) + "/" + str(episode_count)) state = getState(data, 0, window_size + 1) total_profit = 0 agent.inventory = [] - for t in xrange(l): + for t in range(l): action = agent.act(state) # sit @@ -29,22 +29,22 @@ if action == 1: # buy agent.inventory.append(data[t]) - print "Buy: " + formatPrice(data[t]) + print ("Buy: " + formatPrice(data[t])) elif action == 2 and len(agent.inventory) > 0: # sell bought_price = agent.inventory.pop(0) reward = max(data[t] - bought_price, 0) total_profit += data[t] - bought_price - print "Sell: " + formatPrice(data[t]) + " | Profit: " + formatPrice(data[t] - bought_price) + print ("Sell: " + formatPrice(data[t]) + " | Profit: " + formatPrice(data[t] - bought_price)) done = True if t == l - 1 else False agent.memory.append((state, action, reward, next_state, done)) state = next_state if done: - print "--------------------------------" - print "Total Profit: " + formatPrice(total_profit) - print "--------------------------------" + print ("--------------------------------") + print ("Total Profit: " + formatPrice(total_profit)) + print ("--------------------------------") if len(agent.memory) > batch_size: agent.expReplay(batch_size)