def getHistoricData(symbols, **options): ''' get data from Yahoo finance and return pandas dataframe Will get OHLCV data frame if sinle symbol is provided. If many symbols are provided, it will return a wide panel Parameters ------------ symbols: Yahoo finanance symbol or a list of symbols sDate: start date (y,m,d) eDate: end date (y,m,d) adjust : T/[F] adjust data based on adj_close ''' assert isinstance( symbols, (list, str)), 'Input must be a string symbol or a list of symbols' if isinstance(symbols, str): return getSymbolData(symbols, **options) else: data = {} print 'Downloading data:' p = ProgressBar(len(symbols)) for idx, symbol in enumerate(symbols): p.animate(idx + 1) data[symbol] = getSymbolData(symbol, verbose=False, **options) return WidePanel(data)
def _check(frame): dense_frame = frame.to_dense() wp = WidePanel.from_dict({"foo": frame}) from_dense_lp = wp.to_long() from_sparse_lp = spm.stack_sparse_frame(frame) self.assert_(np.array_equal(from_dense_lp.values, from_sparse_lp.values))
def load(self, dataFile): """load data from HDF""" if os.path.exists(dataFile): store = HDFStore(dataFile) symbols = [str(s).strip('/') for s in store.keys()] data = dict(zip(symbols, [store[symbol] for symbol in symbols])) self.wp = WidePanel(data) store.close() else: raise IOError('Data file does not exist')
def downloadData(self,symbols='all'): ''' get data from yahoo ''' if symbols == 'all': symbols = self.symbols #store = HDFStore(self.dataFile) for idx,symbol in enumerate(symbols): print 'Downloading %s [%i/%i]' % (symbol,idx+1,len(symbols)) try: df = getHistoricData(symbol,self.startDate) print 'Got %i samples' % len(df) if self.autoAdjust: df = _adjust(df,removeOrig=True) if len(self.symbols)==0: self.wp = WidePanel({symbol:df}) else: self.wp[symbol] = df except Exception,e: print e
def downloadData(self, symbols='all'): ''' get data from yahoo ''' if symbols == 'all': symbols = self.symbols #store = HDFStore(self.dataFile) p = ProgressBar(len(symbols)) for idx, symbol in enumerate(symbols): try: df = getHistoricData(symbol, self.startDate, verbose=False) if self.autoAdjust: df = _adjust(df, removeOrig=True) if len(self.symbols) == 0: self.wp = WidePanel({symbol: df}) else: self.wp[symbol] = df except Exception, e: print e p.animate(idx + 1)
def __init__(self, autoAdjust=True): self.startDate = (2008, 1, 1) self.autoAdjust = autoAdjust self.wp = WidePanel()
def test_to_dense(self): dwp = self.panel.to_dense() dwp2 = WidePanel.from_dict(self.data_dict) assert_panel_equal(dwp, dwp2)
def test_dense_to_sparse(self): wp = WidePanel.from_dict(self.data_dict) dwp = wp.to_sparse() self.assert_(isinstance(dwp['ItemA']['A'], SparseSeries))