Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I run into a index error when running stock_keras.ipynb first cell. #2

Open
louis78100 opened this issue Jul 28, 2020 · 1 comment
Open

Comments

@louis78100
Copy link

When I run the first cell of the notebook stock_keras.ipynb, i got the following error. This is appearing after doing all the labels for every technical indicators except the IBR.

Here is the context :
running stock_cnn.py ['./train.py', 'WMT', 'original']
../stock_history/WMT
../outputs/fresh_rolling_train
../stock_history/WMT/WMT.csv
1 ) 28-07-2020 16_40_55 MainThread INFO\ Initialized logging at path ../outputs/fresh_rolling_train/logs/log_WMT_original_fresh_rolling_train_28-07-2020_16_40_55.log
Tensorflow devices
path to company data: ../stock_history/WMT/WMT.csv
2 ) 28-07-2020 16_40_55 MainThread DEBUG\ Data for WMT ready to use
3 ) 28-07-2020 16_40_55 MainThread DEBUG\ Technical indicators already calculated. Loading...
4 ) 28-07-2020 16_40_55 MainThread DEBUG\ Dropped 26 nan rows before label calculation
5 ) 28-07-2020 16_40_55 MainThread DEBUG\ creating label with original paper strategy
Calculating labels
HBox(children=(IntProgress(value=0, max=5007), HTML(value='')))

IndexError Traceback (most recent call last)
~/Downloads/stock_cnn_blog_pub-master/src/train.py in
71
72 start_time = time.time()
---> 73 data_gen = DataGenerator(company_code, PATH_TO_COMPANY_DATA, OUTPUT_PATH, strategy_type, False, logger)
74 # exit here, since training is done with stock_keras.ipynb.
75 # comment sys.exit() if you want to try out rolling window training.

~/Downloads/stock_cnn_blog_pub-master/src/data_generator.py in init(self, company_code, data_path, output_path, strategy_type, update, logger)
40 self.update = update
41 self.download_stock_data()
---> 42 self.df = self.create_features()
43 self.feat_idx = self.feature_selection()
44 self.one_hot_enc = OneHotEncoder(sparse=False, categories='auto')

~/Downloads/stock_cnn_blog_pub-master/src/data_generator.py in create_features(self)
266 short = self.strategy_type.split('')[0]
267 long = self.strategy_type.split('
')[1]
--> 268 df['labels'] = self.create_label_short_long_ma_crossover(df, 'close', short, long)
269 else:
270 df['labels'] = self.create_labels(df, 'close')

~/Downloads/stock_cnn_blog_pub-master/src/data_generator.py in create_labels(self, df, col_name, window_size)
142
143 labels[window_middle] = 1
--> 144 else:
145
146 labels[window_middle] = 2

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

@catalinmut
Copy link

In your while loop, window_middle is divided by 2 and it becomes a float.
Cast it back as an integer or you can try to use int(window_middle) instead of window_middle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants