def Options(symbol, data_source=None, session=None): if data_source is None: warnings.warn("Options(symbol) is deprecated, use Options(symbol," " data_source) instead", FutureWarning, stacklevel=2) data_source = "yahoo" if data_source == "yahoo": raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Options')) return YahooOptions(symbol, session=session) elif data_source == "google": raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Google Options')) return GoogleOptions(symbol, session=session) else: raise NotImplementedError("currently only yahoo and google supported")
def __init__(self, symbols, start=None, end=None, retry_count=3, pause=.1, timeout=30, session=None, freq=None, interval='day', span='year'): raise ImmediateDeprecationError(DEP_ERROR_MSG.format("Robinhood")) super(RobinhoodHistoricalReader, self).__init__(symbols, start, end, retry_count, pause, timeout, session, freq) interval_span = { 'day': ['year'], 'week': ['5year'], '10minute': ['day', 'week'], '5minute': ['day', 'week'] } if interval not in interval_span: raise ValueError('Interval must be one of ' '{0}'.format(', '.join(interval_span.keys()))) valid_spans = interval_span[interval] if span not in valid_spans: raise ValueError('For interval {0}, span must ' 'be in: {1}'.format(interval, valid_spans)) self.interval = interval self.span = span self._max_symbols = 75 self._validate_symbols() self._json_results = []
def __init__( self, symbols, start=None, end=None, retry_count=3, pause=0.1, timeout=30, session=None, freq=None, interval="day", span="year", ): raise ImmediateDeprecationError(DEP_ERROR_MSG.format("Robinhood")) super(RobinhoodHistoricalReader, self).__init__(symbols, start, end, retry_count, pause, timeout, session, freq) interval_span = { "day": ["year"], "week": ["5year"], "10minute": ["day", "week"], "5minute": ["day", "week"], } if interval not in interval_span: raise ValueError("Interval must be one of " "{0}".format(", ".join(interval_span.keys()))) valid_spans = interval_span[interval] if span not in valid_spans: raise ValueError("For interval {0}, span must " "be in: {1}".format(interval, valid_spans)) self.interval = interval self.span = span self._max_symbols = 75 self._validate_symbols() self._json_results = []
def __init__(self, symbols=None, start=None, end=None, retry_count=3, pause=0.001, session=None, chunksize=25): raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Google finance')) super(GoogleDailyReader, self).__init__(symbols, start, end, retry_count, pause, session, chunksize)
def _get_data(idx_sym): # pragma: no cover """ Returns DataFrame containing list of component information for index represented in idx_sym from yahoo. Includes component symbol (ticker), exchange, and name. Parameters ---------- idx_sym : str Stock index symbol Examples: '^DJI' (Dow Jones Industrial Average) '^NYA' (NYSE Composite) '^IXIC' (NASDAQ Composite) See: http://finance.yahoo.com/indices for other index symbols Returns ------- idx_df : DataFrame """ raise ImmediateDeprecationError(DEP_ERROR_MSG.format("Yahoo Components")) stats = "snx" # URL of form: # http://download.finance.yahoo.com/d/quotes.csv?s=@%5EIXIC&f=snxl1d1t1c1ohgv url = _URL + "s={0}&f={1}&e=.csv&h={2}" idx_mod = idx_sym.replace("^", "@%5E") url_str = url.format(idx_mod, stats, 1) idx_df = DataFrame() mask = [True] comp_idx = 1 # LOOP across component index structure, # break when no new components are found while True in mask: url_str = url.format(idx_mod, stats, comp_idx) with urlopen(url_str) as resp: raw = resp.read() lines = raw.decode("utf-8").strip().strip('"').split('"\r\n"') lines = [line.strip().split('","') for line in lines] temp_df = DataFrame(lines, columns=["ticker", "name", "exchange"]) temp_df = temp_df.drop_duplicates() temp_df = temp_df.set_index("ticker") mask = ~temp_df.index.isin(idx_df.index) comp_idx = comp_idx + 50 idx_df = idx_df.append(temp_df[mask]) return idx_df
def __init__(self, symbols, start=None, end=None, retry_count=3, pause=.1, timeout=30, session=None, freq=None): raise ImmediateDeprecationError(DEP_ERROR_MSG.format("Robinhood")) super(RobinhoodQuoteReader, self).__init__(symbols, start, end, retry_count, pause, timeout, session, freq) if isinstance(self.symbols, str): self.symbols = [self.symbols] self._max_symbols = 1630 self._validate_symbols() self._json_results = []
def __init__( self, dataset_id=None, api_key=None, retry_count=5, pause=0.75, session=None, base_url="https://public.enigma.com/api", ): raise ImmediateDeprecationError(DEP_ERROR_MSG.format("Enigma")) super(EnigmaReader, self).__init__( symbols=[], retry_count=retry_count, pause=pause, session=session ) if api_key is None: self._api_key = os.getenv("ENIGMA_API_KEY") if self._api_key is None: raise ValueError( "Please provide an Enigma API key or set " "the ENIGMA_API_KEY environment variable\n" "If you do not have an API key, you can get " "one here: http://public.enigma.com/signup" ) else: self._api_key = api_key self._dataset_id = dataset_id if not isinstance(self._dataset_id, string_types): raise ValueError( "The Enigma dataset_id must be a string (ex: " "'bedaf052-5fcd-4758-8d27-048ce8746c6a')" ) headers = { "Authorization": "Bearer {0}".format(self._api_key), "User-Agent": "pandas-datareader", } self.session.headers.update(headers) self._base_url = base_url self._retry_count = retry_count self._retry_delay = pause
def __init__(self, symbols=None, retry_count=3, pause=0.1, session=None, api_key=None): raise ImmediateDeprecationError(DEP_ERROR_MSG.format("AVQuotesReader")) if isinstance(symbols, str): syms = [symbols] elif isinstance(symbols, list): if len(symbols) > 100: raise ValueError("Up to 100 symbols at once are allowed.") else: syms = symbols super(AVQuotesReader, self).__init__( symbols=syms, start=None, end=None, retry_count=retry_count, pause=pause, session=session, api_key=api_key, )
def __init__(self, symbols, start=None, end=None, retry_count=3, pause=0.1, timeout=30, session=None, freq=None, incl_splits=False, incl_dividends=False, incl_volume=True, currency='usd', interval='d'): raise ImmediateDeprecationError(DEP_ERROR_MSG.format("Morningstar")) super(MorningstarDailyReader, self).__init__(symbols, start, end, retry_count, pause, timeout, session, freq) self.incl_splits = incl_splits self.incl_dividends = incl_dividends self.incl_vol = incl_volume self.currency = currency self.interval = interval
def get_quote_google(*args, **kwargs): raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Google Quotes')) return GoogleQuotesReader(*args, **kwargs).read()
def get_quote_yahoo(*args, **kwargs): raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions')) return YahooQuotesReader(*args, **kwargs).read()
def get_data_yahoo_actions(*args, **kwargs): raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions')) return YahooActionReader(*args, **kwargs).read()
def DataReader(name, data_source=None, start=None, end=None, retry_count=3, pause=0.001, session=None, access_key=None): """ Imports data from a number of online sources. Currently supports Google Finance, St. Louis FED (FRED), and Kenneth French's data library, among others. Parameters ---------- name : str or list of strs the name of the dataset. Some data sources (google, fred) will accept a list of names. data_source: {str, None} the data source ("google", "fred", "ff") start : {datetime, None} left boundary for range (defaults to 1/1/2010) end : {datetime, None} right boundary for range (defaults to today) retry_count : {int, 3} Number of times to retry query request. pause : {numeric, 0.001} Time, in seconds, to pause between consecutive queries of chunks. If single value given for symbol, represents the pause between retries. session : Session, default None requests.sessions.Session instance to be used access_key : (str, None) Optional parameter to specify an API key for certain data sources. Examples ---------- # Data from Google Finance aapl = DataReader("AAPL", "google") # Price and volume data from IEX tops = DataReader(["GS", "AAPL"], "iex-tops") # Top of book executions from IEX gs = DataReader("GS", "iex-last") # Real-time depth of book data from IEX gs = DataReader("GS", "iex-book") # Data from FRED vix = DataReader("VIXCLS", "fred") # Data from Fama/French ff = DataReader("F-F_Research_Data_Factors", "famafrench") ff = DataReader("F-F_Research_Data_Factors_weekly", "famafrench") ff = DataReader("6_Portfolios_2x3", "famafrench") ff = DataReader("F-F_ST_Reversal_Factor", "famafrench") """ if data_source == "yahoo": raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Daily')) return YahooDailyReader(symbols=name, start=start, end=end, adjust_price=False, chunksize=25, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "yahoo-actions": raise ImmediateDeprecationError(DEP_ERROR_MSG.format('Yahoo Actions')) return YahooActionReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "yahoo-dividends": comp = 'Yahoo Dividends' raise ImmediateDeprecationError(DEP_ERROR_MSG.format(comp)) return YahooDivReader(symbols=name, start=start, end=end, adjust_price=False, chunksize=25, retry_count=retry_count, pause=pause, session=session, interval='d').read() elif data_source == "google": return GoogleDailyReader(symbols=name, start=start, end=end, chunksize=25, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "iex": return IEXDailyReader(symbols=name, start=start, end=end, chunksize=25, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "iex-tops": return IEXTops(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "iex-last": return IEXLasts(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "bankofcanada": return BankOfCanadaReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "stooq": return StooqDailyReader(symbols=name, chunksize=25, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "iex-book": return IEXDeep(symbols=name, service="book", start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "enigma": return EnigmaReader(dataset_id=name, api_key=access_key).read() elif data_source == "fred": return FredReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "famafrench": return FamaFrenchReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "oecd": return OECDReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "eurostat": return EurostatReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "edgar-index": raise ImmediateDeprecationError(DEP_ERROR_MSG.format('EDGAR')) return EdgarIndexReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == 'nasdaq': if name != 'symbols': raise ValueError("Only the string 'symbols' is supported for " "Nasdaq, not %r" % (name, )) return get_nasdaq_symbols(retry_count=retry_count, pause=pause) elif data_source == "quandl": return QuandlReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "moex": return MoexReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == "morningstar": return MorningstarDailyReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session, interval="d").read() elif data_source == 'robinhood': return RobinhoodHistoricalReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session).read() elif data_source == 'tiingo': return TiingoDailyReader(symbols=name, start=start, end=end, retry_count=retry_count, pause=pause, session=session, api_key=access_key).read() else: msg = "data_source=%r is not implemented" % data_source raise NotImplementedError(msg)