Ejemplo n.º 1
0
            #reward = max(data[t] - buying_price, 0)
            #gain += data[t] - buying_price
            if (gain > 0):
                reward = 1
            else:
                reward = 0
            print("Sell: " + formatPrice(data[t]) + " | Profit: " +
                  formatPrice(data[t] - buying_price) + "| Portfolio Value: " +
                  formatPrice(broker.portfolio) + "| Inventory Size:" +
                  str(len(broker.trades_list)))
        elif action == 0:  # hold
            print("Hold | Portfolio Value: " + formatPrice(broker.portfolio) +
                  "| Inventory Size:" + str(len(broker.trades_list)))
            reward = 0

        done = True if t == data_size - 1 else False
        next_state = getState(data, t + 1, state_size + 1)
        broker.memory.append((state, action, reward, next_state, done))
        state = next_state

        if done:
            print("_________________________________")
            print("Epoch {0} Profit \n:".format(str(e)) + formatPrice(gain))

        if len(broker.memory) > batch_size:
            broker.expReplay(batch_size)

    if e % 20 == 0:
        broker.model.save("models/" + stock_name + "_ep_" + str(e))