diff --git a/train.py b/train.py index c4ba8ed..b35e77e 100644 --- a/train.py +++ b/train.py @@ -11,7 +11,7 @@ agent = Agent(window_size) data = getStockDataVec(stock_name) l = len(data) - 1 -batch_size = 32 +batch_size = 64 for e in xrange(episode_count + 1): print "Episode " + str(e) + "/" + str(episode_count) @@ -19,6 +19,8 @@ total_profit = 0 agent.inventory = [] + b=0 + a=0 for t in xrange(l): action = agent.act(state) @@ -26,18 +28,26 @@ # sit next_state = getState(data, t + 1, window_size + 1) reward = 0 + a+=1 if action == 1: # buy agent.inventory.append(data[t]) print "Buy: " + formatPrice(data[t]) + b=b+1 + a=0 elif action == 2 and len(agent.inventory) > 0: # sell bought_price = agent.inventory.pop(0) - reward = max(data[t] - bought_price, 0) + reward =(data[t] - bought_price)*100 total_profit += data[t] - bought_price + b=0 + a=0 print "Sell: " + formatPrice(data[t]) + " | Profit: " + formatPrice(data[t] - bought_price) + if(b>10 or a>20): + reward+=-200 done = True if t == l - 1 else False + agent.memory.append((state, action, reward, next_state, done)) state = next_state