-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseline Example.py
More file actions
32 lines (24 loc) · 831 Bytes
/
Baseline Example.py
File metadata and controls
32 lines (24 loc) · 831 Bytes
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
import gym
import numpy as np
import gym_anytrading
from stable_baselines import A2C
from stable_baselines.common.vec_env import DummyVecEnv
import matplotlib.pyplot as plt
env_maker = lambda: gym.make('forex-v0', window_size = 100, frame_bound = (100, 1000))
env = DummyVecEnv([env_maker])
policy_kwargs = dict(net_arch=[64, 'lstm', dict(vf=[128, 128, 128], pi=[64, 64])])
model = A2C('MlpLstmPolicy', env, verbose=1, policy_kwargs=policy_kwargs)
model.learn(total_timesteps=10000)
env = env_maker()
observation = env.reset()
while True:
observation = observation[np.newaxis, ...]
#action = env.action_space.sample()
action, _states = model.predict(observation)
observation, reward, done, info = env.step(action)
if done:
print("info:", info)
break
plt.cla()
env.render_all()
plt.show()