def run_stock(): n_epoch = 100 mean = [] for x in range(n_epoch): env = Env(STOCK.Baidu) env.set_count(999) # from 1000 to 2000 for i in range(1000): action = random.random() * 2 - 1 # [-1, 1] env.step(action) mean.append(env.asset - 10000) # while True: # action = random.random() * 2 - 1 # [-1, 1] # observation_, reward, done = env.step(action) # # if done: # mean.append(env.asset - 10000) # break print(np.mean(mean), np.var(mean)) # end of game print('game over')
from stock_env_discrete import StockEnv as StockEnvD from stock_env_discrete import STOCK as STOCKD from sklearn.externals import joblib import warnings if __name__ == '__main__': warnings.filterwarnings("ignore") # ignore warnings stockHMM = StockHMM(STOCK.Baidu) # load model stockHMM.model = joblib.load("BaiDuHMM.pkl") print('Continuous: ') env = StockEnv(STOCK.Baidu) # [1000, 2000) env.set_count(999) for x in range(1000): p_states = stockHMM.predict(x + 1000) # order: 2 3 4 1 0 my_action = p_states[ 2] + p_states[3] * 0.5 - p_states[1] * 0.5 - p_states[0] env.step(my_action) print(env.asset - 10000) print('Discrete: ') env = StockEnvD(STOCKD.Baidu) # [1000, 2000) env.set_count(999) for x in range(1000): p_states = stockHMM.predict(x + 1000)