def _load_data(self, strpcons, dt_start, dt_end, n, spec_date): all_data = OrderedDict() max_window = -1 logger.info("loading data...") pbar = ProgressBar().start() for i, pcon in enumerate(strpcons): #print "load data: %s" % pcon if pcon in spec_date: dt_start = spec_date[pcon][0] dt_end = spec_date[pcon][1] assert(dt_start < dt_end) if n: wrapper = self._data_manager.get_last_bars(pcon, n) else: wrapper = self._data_manager.get_bars(pcon, dt_start, dt_end) if len(wrapper) == 0: continue all_data[pcon] = DataContext(wrapper) max_window = max(max_window, len(wrapper)) pbar.update(i*100.0/len(strpcons)) #progressbar.log('') if n: assert(max_window <= n) pbar.finish() if len(all_data) == 0: assert(False) ## @TODO raise return all_data, max_window
def _load_data(self, strpcons, dt_start, dt_end, n, spec_date): all_data = OrderedDict() max_window = -1 logger.info("loading data...") pbar = ProgressBar().start() pcontracts = [PContract.from_string(s) for s in strpcons] pcontracts = sorted(pcontracts, reverse=True) for i, pcon in enumerate(pcontracts): strpcon = str(pcon) if strpcon in spec_date: dt_start = spec_date[strpcon][0] dt_end = spec_date[strpcon][1] assert (dt_start < dt_end) if n: wrapper = self._data_manager.get_last_bars(strpcon, n) else: wrapper = self._data_manager.get_bars(strpcon, dt_start, dt_end) if len(wrapper) == 0: continue all_data[strpcon] = DataContext(wrapper) max_window = max(max_window, len(wrapper)) pbar.update(i * 100.0 / len(strpcons)) # progressbar.log('') if n: assert (max_window <= n) pbar.finish() if len(all_data) == 0: assert (False) # @TODO raise return all_data, max_window
def load_data(self, strpcon, dt_start=datetime(1980, 1, 1), dt_end=datetime(2100, 1, 1)): """ 加载周期合约数据 Args: strpcon (str): 周期合约 dt_start(datetime): 开始时间 dt_end(datetime): 结束时间 Returns: pd.DataFrame. k线数据 """ strpcon = strpcon.upper() try: return self.all_data[strpcon] except KeyError: wrapper = self._data_manager.get_bars(strpcon, dt_start, dt_end, self._window_size) window_size = len( wrapper.data) if not series.g_rolling else self._window_size self.all_data[strpcon] = DataContext(wrapper, window_size) return wrapper