Iterates over all symbols and collects their data
(self)
| 156 | return volatility |
| 157 | |
| 158 | def collect_data_for_all_tickers(self): |
| 159 | """ |
| 160 | Iterates over all symbols and collects their data |
| 161 | """ |
| 162 | |
| 163 | print("Loading data for all stocks...") |
| 164 | features = [] |
| 165 | symbol_names = [] |
| 166 | historical_price_info = [] |
| 167 | future_price_info = [] |
| 168 | |
| 169 | # Any stock with very low volatility is ignored. You can change this line to address that. |
| 170 | for i in tqdm(range(len(self.stocks_list))): |
| 171 | symbol = self.stocks_list[i] |
| 172 | try: |
| 173 | stock_price_data, future_prices, not_found = self.get_data(symbol) |
| 174 | |
| 175 | if not not_found: |
| 176 | volatility = self.calculate_volatility(stock_price_data) |
| 177 | |
| 178 | # Filter low volatility stocks |
| 179 | if volatility < self.VOLATILITY_THRESHOLD: |
| 180 | continue |
| 181 | |
| 182 | features_dictionary = self.taEngine.get_technical_indicators(stock_price_data) |
| 183 | feature_list = self.taEngine.get_features(features_dictionary) |
| 184 | |
| 185 | # Add to dictionary |
| 186 | self.features_dictionary_for_all_symbols[symbol] = {"features": features_dictionary, "current_prices": stock_price_data, "future_prices": future_prices} |
| 187 | |
| 188 | # Save dictionary after every 100 symbols |
| 189 | if len(self.features_dictionary_for_all_symbols) % 100 == 0 and self.IS_SAVE_DICT == 1: |
| 190 | np.save(self.DICT_PATH, self.features_dictionary_for_all_symbols) |
| 191 | |
| 192 | if np.isnan(feature_list).any() == True: |
| 193 | continue |
| 194 | |
| 195 | # Check for volume |
| 196 | average_volume_last_30_tickers = np.mean(list(stock_price_data["Volume"])[-30:]) |
| 197 | if average_volume_last_30_tickers < self.VOLUME_FILTER: |
| 198 | continue |
| 199 | |
| 200 | # Add to lists |
| 201 | features.append(feature_list) |
| 202 | symbol_names.append(symbol) |
| 203 | historical_price_info.append(stock_price_data) |
| 204 | future_price_info.append(future_prices) |
| 205 | |
| 206 | except Exception as e: |
| 207 | print("Exception", e) |
| 208 | continue |
| 209 | |
| 210 | # Sometimes, there are some errors in feature generation or price extraction, let us remove that stuff |
| 211 | features, historical_price_info, future_price_info, symbol_names = self.remove_bad_data(features, historical_price_info, future_price_info, symbol_names) |
| 212 | |
| 213 | return features, historical_price_info, future_price_info, symbol_names |
| 214 | |
| 215 | def load_data_from_dictionary(self): |
no test coverage detected