July 2019
Beginner to intermediate
740 pages
16h 52m
English
Collecting data for individual stocks is just as easy with the get_ticker_data() method of the StockReader; this time, it will use data from Investors Exchange (IEX). In the following method, we try to get the data from IEX, but if there is an issue doing so, we get it from Yahoo! Finance (except):
@label_sanitizerdef get_ticker_data(self, ticker): """ Get historical OHLC data for given date range and ticker. Parameter: - ticker: The stock symbol to lookup as a string. Returns: A pandas dataframe with the stock data. """ try: data = web.DataReader(ticker, 'iex', self.start, self.end) data.index = pd.to_datetime(data.index) except: # get it from Yahoo! Finance if it doesn't work data = web.get_data_yahoo(ticker, ...
Read now
Unlock full access