-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrun_simulations.py
47 lines (39 loc) · 1.38 KB
/
run_simulations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from datetime import date
from logging import INFO
import shutil
import gym
import asx_gym
# from agents.buy_and_keep_agent import BuyAndKeepAgent
from agents.random_agent import RandomAgent
from asx_gym.envs import AsxObservation
def main():
try:
shutil.rmtree('images')
print("delete images directory")
except OSError as e:
print("Error: %s : %s" % ('images', e.strerror))
gym.logger.set_level(INFO)
start_date = date(2019, 5, 1)
simulate_company_list = [2, 3, 4, 5, 6, 44, 300, 67, 100, 200]
# simulate_company_list = [3]
env = gym.make("AsxGym-v0", start_date=start_date,
simulate_company_list=simulate_company_list)
stock_agent = RandomAgent(env)
# stock_agent = RandomAgent(env, min_volume=100, max_volume=500)
# stock_agent = BuyAndKeepAgent(env, 3)
observation = env.reset()
for _ in range(200000 * 24):
env.render()
company_count = len(env.simulate_company_list)
observation, reward, done, info = env.step(stock_agent.action())
if done:
env.insert_summary_images(30)
observation = env.reset()
stock_agent.reset()
if observation is not None:
asx_observation = AsxObservation(observation)
print(asx_observation.to_json_obj())
print(info)
env.close()
if __name__ == "__main__":
main()