PacktPublishing / Deep-Reinforcement-Learning-Hands-On-Second-Edition

Deep-Reinforcement-Learning-Hands-On-Second-Edition, published by Packt
MIT License
1.17k stars 545 forks source link

Chapter 10 Stocks Trading: Getting Error in "class StocksEnv(gym.Env):" #69

Closed ManojAgrawal closed 7 months ago

ManojAgrawal commented 1 year ago

Hello, I am trying to run the code as it is in

Chapter10/lib/environ.py

image

but I get an error


TypeError Traceback (most recent call last) /var/folders/_s/1nlhtzmx7776vpsb0yjhzdq00000gp/T/ipykernel_85372/2865701658.py in ----> 1 class StocksEnv(gym.Env): 2 metadata = {'render.modes': ['human']} 3 spec = EnvSpec("StocksEnv-v0") 4 5 def init(self, prices, bars_count=DEFAULT_BARS_COUNT,

/var/folders/_s/1nlhtzmx7776vpsb0yjhzdq00000gp/T/ipykernel_85372/2865701658.py in StocksEnv() 1 class StocksEnv(gym.Env): 2 metadata = {'render.modes': ['human']} ----> 3 spec = EnvSpec("StocksEnv-v0") 4 5 def init(self, prices, bars_count=DEFAULT_BARS_COUNT,

TypeError: init() missing 1 required positional argument: 'entry_point'

could you please help?

thanks

rajat-packt commented 7 months ago

Hey @ManojAgrawal, it won't be possible to get in touch with the author for some time as they are busy with other commitments, please try this potential solution:

It looks like you're encountering a TypeError because you've defined a class StocksEnv that inherits from gym.Env, but you're missing the required parameters for the EnvSpec constructor when defining the spec attribute.

The EnvSpec constructor requires at least one positional argument, which is the entry_point parameter specifying the entry point for the environment registration. You can resolve this error by providing the entry_point parameter in the EnvSpec definition.

Here's how you can modify your code to include the required entry_point parameter:

class StocksEnv(gym.Env):
    metadata = {'render.modes': ['human']}
    spec = EnvSpec("StocksEnv-v0", entry_point='your_module:StocksEnv')

    def __init__(self, prices, bars_count=DEFAULT_BARS_COUNT,
                 commission=DEFAULT_COMMISSION_PERC,
                 reset_on_close=True, state_1d=False,
                 random_ofs_on_reset=True, reward_on_close=False,
                 volumes=False):
        # Your initialization code here

Replace 'your_module:StocksEnv' with the appropriate module path and class name where StocksEnv is defined. This should resolve the TypeError you're encountering.

I'll be closing this issue now. If you still need help, feel free to reopen or create a new issue.