INNER CODE UNIT · Python
training_agent
adminho/trading-stock-thailand · DeepQ_trade.py:124
def training_agent(symbol, startDate, endDate, total_episode = 100):
start_time = time.time()
# set Environment for trading
env = Environment(symbol, startDate, endDate)
agent = DeepQAgent(env)
all_gain, all_pic = [], []
for episode in range(0, total_episode):
print("\n==================== Episode: %s ====================" % (episode+1))
terminate =False
env.reset()
s_t = env.first_state # get first state from environment
port = env.getPortfolio() # get portfolio
step_observe = 0 # count steps to observe before training my neural network model in Agent
while( terminate != True ):
# agent select (a_t): random action (Exploration) or the best action (depend the epsilon value)
a_t = agent.getAction(s_t)
# Execute action a_t in Environment