Kismuz / btgym

Scalable, event-driven, deep-learning-friendly backtesting library
https://kismuz.github.io/btgym/
GNU Lesser General Public License v3.0
985 stars 260 forks source link

running setting_up_environment_full raise an error #28

Closed djoffrey closed 6 years ago

djoffrey commented 6 years ago

Hi, it is so nice that you wrote these two setting up notebook, it helps a lot, but when I was running the example/setting_up_environment_full,I got these error messages, could you help me out?

env.reset()
take_some_steps(env, 100)
render_all_modes(env)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
~/projects/btgym/btgym/envs/backtrader.py in _reset(self, state_only)
    606             try:
--> 607                 assert self.observation_space.contains(self.env_response[0])
    608 

AssertionError: 

During handling of the above exception, another exception occurred:

AssertionError                            Traceback (most recent call last)
<ipython-input-10-af63753eff47> in <module>()
----> 1 env.reset()
      2 take_some_steps(env, 100)
      3 render_all_modes(env)

~/.pyenv/versions/miniconda3-4.3.11/lib/python3.6/site-packages/gym/core.py in reset(self)
    102             space.
    103         """
--> 104         return self._reset()
    105 
    106     def render(self, mode='human', close=False):

~/projects/btgym/btgym/envs/backtrader.py in _reset(self, state_only)
    632                 self.log.error(msg)
    633                 self._stop_server()
--> 634                 raise AssertionError(msg)
    635 
    636             if state_only:

AssertionError: 
State observation shape/range mismatch!
Space set by env: 

price_gradients:
   Box(30, 4), low: 0.0, high: 1.0

raw_state:
   Box(30, 4), low: 1.03522, high: 1.1616

Space returned by server: 

raw_state:
   array of shape: (4, 4), low: 1.11363, high: 1.11372

price_gradients:
   array of shape: (4, 4), low: 0.3965167501352529, high: 0.6726070170682124

Full response:
{'raw_state': array([[ 1.11372,  1.11372,  1.1137 ,  1.11371],
       [ 1.1137 ,  1.1137 ,  1.11369,  1.11369],
       [ 1.11369,  1.11371,  1.11363,  1.11371],
       [ 1.1137 ,  1.11372,  1.11369,  1.11372]]), 'price_gradients': array([[ 0.44028635,  0.44028635,  0.47003595,  0.44028635],
       [ 0.45512111,  0.4850045 ,  0.39651675,  0.5       ],
       [ 0.5       ,  0.52996405,  0.5       ,  0.54487889],
       [ 0.52996405,  0.52996405,  0.67260702,  0.52996405]])}
Reward: 0.0
Done: False
Info:
{'step': 5, 'time': datetime.datetime(2016, 7, 4, 0, 7), 'action': 'hold', 'broker_message': '-', 'broker_cash': 100.0, 'broker_value': 100.0, 'drawdown': 0.0, 'max_drawdown': 0.0}

Hint: Wrong Strategy.get_state() parameters?
Kismuz commented 6 years ago

@djoffrey , oops my mistake, corrected, update package. As error log says, state shape was defined as:

    state_shape={
        'raw_state': spaces.Box(low=-10, high=10, shape=(30,4)),
        'price_gradients': spaces.Box(low=0, high=1, shape=(30,4))
    },

but should be:

    state_shape={
        'raw_state': spaces.Box(low=-10, high=10, shape=(4,4)),
        'price_gradients': spaces.Box(low=0, high=1, shape=(4,4))
    },
djoffrey commented 6 years ago

@Kismuz Thanks, I don't got enough understanding of all these staff right now, so your notebook and answer helps me a lot!