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")
#-*- coding:utf-8 -*- """boll分仓, 择时策略""" import sys import numpy as np import pandas as pd, pylab as pl from autoxd.strategy import boll_pramid from autoxd import backtest_policy, stock, myenum, agl, account as ac, help, myredis, sign_observation as so, ui if sys.version > '3': from autoxd.pinyin import stock_pinyin3 as jx else: from autoxd import stock_pinyin as jx import os, warnings from autoxd.stock import DataSources agl.tic() class BollFenCangKline(boll_pramid.Strategy_Boll_Pre): """基于日线的boll分仓, 基本指标使用日线Boll以及日线Four""" def setParams(self, *args, **kwargs): self.base_num = 100 #第一次买卖的数量 self.fenchang = [ [-0.05, 0.05, 0], [-0.12, 0.07, 0], [-0.2, 0.1, 0], [-0.3, 0.1, 0], [-0.4, 0.1, 0], [-0.45, 0.2, 0], [-0.5, 0.2, 0], ] #跌幅, 当前资金占比