Git Product home page Git Product logo

Comments (8)

AminHP avatar AminHP commented on September 28, 2024 2

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.

AminHP avatar AminHP commented on September 28, 2024

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.

simonesalvucci avatar simonesalvucci commented on September 28, 2024

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.

AminHP avatar AminHP commented on September 28, 2024

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.

simonesalvucci avatar simonesalvucci commented on September 28, 2024

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...

Screenshot 2020-01-30 at 13 45 08

from gym-anytrading.

AminHP avatar AminHP commented on September 28, 2024

Can you show me your code?

from gym-anytrading.

simonesalvucci avatar simonesalvucci commented on September 28, 2024
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.

simonesalvucci avatar simonesalvucci commented on September 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.