Comments (8)
The problem is something inside the DummyVecEnv
which resets the environment automatically after it is done.
Also, there was a mistake in your code. Try this:
env_maker = lambda: gym.make('forex-v0', frame_bound=(100, 5000), window_size=10)
env = DummyVecEnv([env_maker])
# Training Env
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=1000)
# Testing Env
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)
# env.render()
if done:
print("info:", info)
break
# Plotting results
plt.cla()
env.render_all()
plt.show()
from gym-anytrading.
Hi.
I took a look at the source code of the DummyVecEnv
here. It seems you should use env.envs[0].render_all()
.
I didn't test it, so please check it out and let me know if it works.
from gym-anytrading.
Thank you @AminHP
It worked, but there was another issue in render_all()
.
line 140 in render_all
if self._position_history[i] == Positions.Short:
IndexError: list index out of range
from gym-anytrading.
It seems the problem is solved. Try to remove your gym-anytrading
and install it using the command below:
pip install https://github.com/AminHP/gym-anytrading/archive/master.zip
from gym-anytrading.
The IndexError is fixed now, thank you.
But I think there is still something wrong going on, I've tried to debug the Environment unsuccessful.
What I get from render_all()
is a plot with just one short position, which is very weird...
from gym-anytrading.
Can you show me your code?
from gym-anytrading.
env = DummyVecEnv([lambda: gym.make('forex-v0', frame_bound=(100, 5000), window_size=10)])
# Training Env
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=1000)
# Testing Env
observation = env.reset()
while True:
# action = env.action_space.sample()
action = model.predict(observation)
observation, reward, done, info = env.step(action)
# env.render()
if done:
print("info:", info)
break
# Plotting results
plt.cla()
env.envs[0].render_all()
plt.show()
from gym-anytrading.
Thank you @AminHP
I must have missed the reset of the environment in DummyVecEnv
.
Now it makes much more sense.
The code above works perfectly!
from gym-anytrading.
Related Issues (20)
- Do the trading environments only allow for 1 share to be held at a time? HOT 2
- NameNotFound: Environment forex doesn't exist. ,NameNotFound: Environment stocks doesn't exist. HOT 2
- Some questions
- TypeError: Argument 'placement' has incorrect type (expected pandas._libs.internals.BlockPlacement, got slice)
- Question on step reward
- How to obtain a single prediction from trained model? HOT 1
- On training how to set the frame_bound? HOT 2
- Feature Request: update from gym to gymnasium HOT 3
- _calculate_reward modify HOT 1
- Campatibility with TF-Agents HOT 1
- how to use multi time-frame to create custom environment HOT 1
- Balance, order volume is not explained in the docs. Reward gaming behavior observed in some models. HOT 3
- Same model behaves differently when run on different machines HOT 4
- Does anybody understand this block of code from the MtEnv class in the env directory. Most especially the currency_profit.
- New version of gym ERROR: Environment stocks doesn't exist HOT 9
- NOT A BUG - General Help: Observation Spaces do not match HOT 1
- Tensor conversion error when trying to use TF-Agents with Anytrading HOT 2
- Add render_mode='rgb_array' HOT 2
- ModuleNotFoundError: No module named 'your_module' HOT 2
- Unable to evaluate models HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gym-anytrading.