def test(): agent = DQN() code = jx.YHGF洋河股份 df = trading_gym.getData(code) #为了测试缩短df test_len = int(len(df) * 0.2) df = df[-test_len:] df = trading_gym.genTradeDf(df, int(len(df) / 10)) #train env = trading_gym.ATgymEnv(code, df) for i in range(30): #现在的速度一天只能跑30次 observation = env.reset() assert (observation is not None) reward_total = 0 agl.tic() while True: try: env.render() time.sleep(.05) except: pass action = agent.egreedy_action(observation) #print('action=', action) next_observation, reward, done, info = env.step(action) #print('observation=', str(next_observation.shape)) observation = next_observation #print('%d,%d', action, reward) #print('reward=', reward) reward_total += reward if done: print('[%d]reward_total=' % i, reward_total) print( AccountMgr(env.account, df.iloc[-1]['c'], env.code).total_money()) agl.toc() break
def main(args): agl.tic() BackTestPolicy.Test() agl.toc() print("end")
code = options.code if code == 'next': code = MyCode.get() codes = stock.get_codes() codes = np.array(codes) index = int(np.argwhere(codes == code)) if index +1 < len(codes): code = codes[index+1] MyCode.set(code) print("index=%d"%(index)) else: print("end") else: MyCode.set(code) print("current_code=%s"%(code)) else: print('\t--single\t单进程执行\n\t--multi\t多进程执行\n\t--second \t第二阶段\n\t--code=code or next\t\n') #run_myclust() if options.single is not None: test_myhclust() elif options.multi is not None: test_multi_myhclust() elif options.second is not None: test_second_myhclust() elif options.genimg is not None: code = MyCode.get() genImgToFile(code) agl.toc()