Kismuz / btgym

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

Multi asset example notebook crash #83

Closed shikharbhardwaj closed 5 years ago

shikharbhardwaj commented 5 years ago

The multi asset example notebook crashes with the traceback:

Process BTgymDataFeedServer-2:1:                                               
Traceback (most recent call last):                                                                                
  File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()                                                                            
  File "/home/shikhar/dev/btgym/btgym/dataserver.py", line 175, in run                    
    sample = self.get_data(sample_config=service_input['kwargs'])                        
  File "/home/shikhar/dev/btgym/btgym/dataserver.py", line 87, in get_data               
    sample = self.dataset.sample(**sample_config)                            
  File "/home/shikhar/dev/btgym/btgym/datafeed/multi.py", line 209, in sample 
    master_sample = self.master_data.sample(**kwargs)                          
  File "/home/shikhar/dev/btgym/btgym/datafeed/casual.py", line 516, in sample        
    **kwargs                                                                           
  File "/home/shikhar/dev/btgym/btgym/datafeed/base.py", line 812, in _sample_interval 
    if interval[-1] - interval[0] + self.max_gap_num_records > self.sample_num_records:                           
AttributeError: 'BTgymCasualDataDomain' object has no attribute 'max_gap_num_records'       

Running environment:
Files or part of package has been run:

btgym/examples/multi_discrete_setup_intro.ipynb

Expected behaviour:

The DataFeed server should not crash.

Actual behaviour:

The DataFeed server crashes when the example is run.

Steps to reproduce:

Run the example in btgym/examples/multi_discrete_setup_intro.ipynb

Fix:
diff --git a/btgym/datafeed/base.py b/btgym/datafeed/base.py
index 12010ff..655be92 100644
--- a/btgym/datafeed/base.py
+++ b/btgym/datafeed/base.py
@@ -221,6 +221,7 @@ class BTgymBaseData:
         self.test_range_delta = None
         self.train_range_delta = None
         self.test_num_records = 0
+        self.max_gap_num_records = 0
         self.train_num_records = 0
         self.total_num_records = 0
         self.train_interval = [0, 0]

I just wanted to check if I am making some obvious mistake in understanding the usage of the example which causes this error.

Kismuz commented 5 years ago

@shikharbhardwaj , sorry for late replay; seems it is bug in code; will fix, ETA 2 days

Kismuz commented 5 years ago

@shikharbhardwaj, fixed, update pkg; thanks for spotting it out.

shikharbhardwaj commented 5 years ago

Thanks for the fix :)