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

Errors running examples in Jupyter notebook #2

Closed shokimble closed 7 years ago

shokimble commented 7 years ago

Hi again,

I'm still having problems running the basic examples. I noticed you're running python 3 judging on the leftover pyc files. I'm trying with 2.7.11, latest dependencies. It could be a Python 3 vs 2.7 thing but I can't see why, to me it looks like you're not including backtrader when referencing it (but I can see it is included). Somehow it works for you but not me. Example error below:

from btgym import BTgymEnv ​

Simpliest trading environment,

using year-long dataset of one minute bars for EUR/USD currency pair:

MyEnvironment = BTgymEnv(filename='./data/DAT_ASCII_EURUSD_M1_2016.csv',) ​

Print parameters and their default values:

​ for params_name, params_dict in MyEnvironment.params.items(): print('\nParameters [{}] subset: '.format(params_name)) for key, value in params_dict.items(): print('{} : {}'.format(key,value))


AttributeError Traceback (most recent call last)

in () 5 6 ----> 7 MyEnvironment = BTgymEnv(filename='./data/DAT_ASCII_EURUSD_M1_2016.csv',) 8 9 # Print parameters and their default values: btgym/envs/backtrader.pyc in __init__(self, **kwargs) 214 # if no bt.Cerebro() custom subclass has been passed, 215 # get base class Cerebro(), using kwargs on top of defaults: --> 216 self.engine = bt.Cerebro() 217 self.params['engine'].update(self.kwargs['engine']) 218 msg = 'Base Cerebro engine used.' AttributeError: 'module' object has no attribute 'Cerebro' I then try my basic example from my previous issue I get the following error: Traceback (most recent call last): File "test.py", line 27, in verbose=1) File "btgym/envs/backtrader.py", line 261, in __init__ if self.engine.strats[0][0][2]['state_low'] is None or \ KeyError: 'state_low' Any clues? I'm pulling my hair out as I can initialise bt separately in Jupyter and I get the same errors regardless of jupyter or command line.
shokimble commented 7 years ago

Previous issue link: https://github.com/Kismuz/btgym/issues/1

I have performed a git pull and cleared out all the remnant pyc files

I might try python 3 next but scared about mucking up my development environment.

shokimble commented 7 years ago

Yup python3 fixed it completely. All examples and my code runs now. Must be some not immediately obvious difference between 2 and 3.

I'll leave it open in case you want to address compatibility issues but I'm happy using 3.

Kismuz commented 7 years ago

@shokimble, thanks for input. Indeed I have not been testing it with Python 2.

It seems pull is not enough in case of package restructuring. It's better to run pip install --upgrade -e . updated readme with it.

! : There will be major rendering refining in a couple of days; it may lack backward compatibility.