Python pandas_datareader.data.DataReader() Examples

The following are 30 code examples of pandas_datareader.data.DataReader(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas_datareader.data , or try the search function .
Example #1
Source File: generate.py    From catalyst with Apache License 2.0 8 votes vote down vote up
def main():
    symbols = ['AAPL', 'MSFT', 'BRK-A']
    # Specifically chosen to include the AAPL split on June 9, 2014.
    for symbol in symbols:
        data = DataReader(
            symbol,
            'yahoo',
            start='2014-03-01',
            end='2014-09-01',
        )
        data.rename(
            columns={
                'Open': 'open',
                'High': 'high',
                'Low': 'low',
                'Close': 'close',
                'Volume': 'volume',
            },
            inplace=True,
        )
        del data['Adj Close']

        dest = join(here, symbol + '.csv')
        print("Writing %s -> %s" % (symbol, dest))
        data.to_csv(dest, index_label='day') 
Example #2
Source File: stock_reader.py    From stock-analysis with MIT License 6 votes vote down vote up
def get_ticker_data(self, ticker):
        """
        Get historical OHLC data for given date range and ticker.
        Tries to get from Investors Exchange (IEX), but falls back
        to Yahoo! Finance if IEX doesn't have it.

        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:
            data = web.get_data_yahoo(
                ticker, self.start, self.end
            )
        return data 
Example #3
Source File: utils.py    From empyrical with Apache License 2.0 6 votes vote down vote up
def get_fama_french():
    """
    Retrieve Fama-French factors via pandas-datareader
    Returns
    -------
    pandas.DataFrame
        Percent change of Fama-French factors
    """

    start = '1/1/1970'
    research_factors = web.DataReader('F-F_Research_Data_Factors_daily',
                                      'famafrench', start=start)[0]
    momentum_factor = web.DataReader('F-F_Momentum_Factor_daily',
                                     'famafrench', start=start)[0]
    five_factors = research_factors.join(momentum_factor).dropna()
    five_factors /= 100.
    five_factors.index = five_factors.index.tz_localize('utc')

    five_factors.columns = five_factors.columns.str.strip()

    return five_factors 
Example #4
Source File: data.py    From japandas with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def DataReader(symbols, data_source=None, start=None, end=None, appid=None, **kwargs):
    if data_source == 'yahoojp':
        msg = "YahooJPReaderは削除されました https://www.yahoo-help.jp/app/answers/detail/p/546/a_id/93575"
        raise NotImplementedError(msg)
    elif data_source == 'estat':
        return EStatReader(symbols=symbols, appid=appid, **kwargs).read()
    else:
        return data.DataReader(name=symbols, data_source=data_source,
                               start=start, end=end, **kwargs) 
Example #5
Source File: ch4_naive_momentum_strategy2.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #6
Source File: ridge.py    From Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date, output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #7
Source File: ch3_svc.py    From Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #8
Source File: eventbasedbacktester.py    From Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #9
Source File: hd5pandareader.py    From Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #10
Source File: loaders.py    From Quantdom with Apache License 2.0 5 votes vote down vote up
def _get(cls, symbol, date_from, date_to):
        quotes = web.DataReader(
            symbol, cls.source, start=date_from, end=date_to
        )
        if cls.sort_index:
            quotes.sort_index(inplace=True)
        return quotes 
Example #11
Source File: loaders.py    From Quantdom with Apache License 2.0 5 votes vote down vote up
def _get(cls, symbol, date_from, date_to):
        quotes = web.DataReader(
            symbol, cls.source, start=date_from, end=date_to
        )
        quotes['Date'] = pd.to_datetime(quotes.index)
        return quotes 
Example #12
Source File: lasso.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date, output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #13
Source File: lr.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date, output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #14
Source File: scatter.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date, output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #15
Source File: ch3_svc.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #16
Source File: ch4_turtle_trading.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #17
Source File: lr.py    From Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date, output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #18
Source File: ch4_pairs_correlation_init.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(symbols, start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading symbols data')
    except FileNotFoundError:
        print('File not found...downloading the symbols data')
        df = data.DataReader(symbols, 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #19
Source File: ch4_double_moving_average.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #20
Source File: eventbasedbacktester.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #21
Source File: hd5pandareader.py    From Learn-Algorithmic-Trading with MIT License 5 votes vote down vote up
def load_financial_data(start_date, end_date,output_file):
    try:
        df = pd.read_pickle(output_file)
        print('File data found...reading GOOG data')
    except FileNotFoundError:
        print('File not found...downloading the GOOG data')
        df = data.DataReader('GOOG', 'yahoo', start_date, end_date)
        df.to_pickle(output_file)
    return df 
Example #22
Source File: backtest_data_feed_quandl.py    From EliteQuant_Python with Apache License 2.0 5 votes vote down vote up
def _retrieve_online_historical_data(self, symbol):
        """
        Retrieve historical data from web
        """
        if self._data_source == 'yahoo':
            data = web.DataReader(symbol, 'yahoo', self._start_date, self._end_date)
        else:
            data = quandl.get('wiki/'+symbol, start_date=self._start_date, end_date=self._end_date, authtoken='ay68s2CUzKbVuy8GAqxj')
        self._hist_data[symbol] = data
        self._hist_data[symbol]["FullSymbol"] = symbol         # attach symbol to data; it will be merged into _data_stream 
Example #23
Source File: utils.py    From empyrical with Apache License 2.0 5 votes vote down vote up
def get_treasury_yield(start=None, end=None, period='3MO'):
    """
    Load treasury yields from FRED.

    Parameters
    ----------
    start : date, optional
        Earliest date to fetch data for.
        Defaults to earliest date available.
    end : date, optional
        Latest date to fetch data for.
        Defaults to latest date available.
    period : {'1MO', '3MO', '6MO', 1', '5', '10'}, optional
        Which maturity to use.
    Returns
    -------
    pd.Series
        Annual treasury yield for every day.
    """

    if start is None:
        start = '1/1/1970'
    if end is None:
        end = _1_bday_ago()

    treasury = web.DataReader("DGS3{}".format(period), "fred",
                              start, end)

    treasury = treasury.ffill()

    return treasury 
Example #24
Source File: data.py    From prophet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run(self, data, start, end, symbols, source, lookback=0):
        data_start = self.get_data_start(start, lookback)

        # Current caching implementation based on Zipline
        symbols_data = dict()
        for symbol in symbols:
            symbol_path = self.sanitize_name(symbol)
            cache_filename = "{stock}-{start}-{end}.csv".format(
                stock=symbol_path, start=data_start, end=end
            ).replace(':', '-')
            cache_filepath = self.get_cache_filepath(cache_filename)
            if os.path.exists(cache_filepath):
                symbol_data = pd.DataFrame.from_csv(cache_filepath)
            else:
                symbol_data = pdr.DataReader(symbol, source,
                                             data_start, end).sort_index()
                symbol_data.to_csv(cache_filepath)
            symbols_data[symbol] = symbol_data

        symbols_panel = pd.concat(symbols_data).to_panel()
        symbols_panel = symbols_panel.swapaxes('minor', 'major')
        if symbols_panel.empty:
            ProphetException("No data for the range specified:"
                             " %s to %s" % (data_start, end))

        symbols_panel = symbols_panel.fillna(method='ffill')
        symbols_panel = symbols_panel.fillna(method='bfill')
        symbols_panel = symbols_panel.fillna(1.0)
        return symbols_panel.loc[:, ((symbols_panel.major_axis >= data_start)
                                     & (symbols_panel.major_axis <= end))] 
Example #25
Source File: main.py    From python-examples with MIT License 5 votes vote down vote up
def get_data_from_yahoo(reload_sp500=False):
    if reload_sp500:
        tickers = save_sp500_tickers()
    else:
        with open("sp500tickers.pickle", "rb") as f:
            tickers = pickle.load(f)

    if not os.path.exists('stock_dfs'):
        os.makedirs('stock_dfs')

    start = dt.datetime(2000, 1, 1)
    end = dt.datetime(2016, 12, 31)

    for ticker in tickers:

        print(ticker)
        
        if not os.path.exists('stock_dfs/{}.csv'.format(ticker)):
            try:
                df = web.DataReader(ticker, 'yahoo', start, end)
                df.to_csv('stock_dfs/{}.csv'.format(ticker))
            except Exception as ex:
                print('Error:', ex)
        else:
            print('Already have {}'.format(ticker)) 
Example #26
Source File: getSandP.py    From kaggle-code with MIT License 5 votes vote down vote up
def download_stock(stock):
	""" try to query the iex for a stock, if failed note with print """
	try:
		print(stock)
		stock_df = web.DataReader(stock,'yahoo', start_time, now_time)
		stock_df['Name'] = stock
		output_name = stock + '_data.csv'
		stock_df.to_csv(output_name)
	except:
		bad_names.append(stock)
		print('bad: %s' % (stock)) 
Example #27
Source File: data.py    From ffn with MIT License 5 votes vote down vote up
def _download_web(name, **kwargs):
    """
    Thin wrapper to enable memoization
    """
    return pdata.DataReader(name, **kwargs) 
Example #28
Source File: fetch.py    From pinkfish with MIT License 5 votes vote down vote up
def fetch_timeseries(symbol, dir_name='data', use_cache=True, from_year=None):
    """
    Read time series data. Use cached version if it exists and
    use_cache is True, otherwise retrive, cache, then read.
    """
    if from_year is None:
        from_year = 1900 if not sys.platform.startswith('win') else 1971

    # yahoo finance uses '-' where '.' is used in symbol names
    symbol = symbol.replace('.', '-')
    symbol = symbol.upper()
    
    # pinkfish allows the use of a suffix starting with a '_',
    # like SPY_SHRT, so extract the symbol
    symbol = symbol.split('_')[0]
    
    timeseries_cache = os.path.join(_get_cache_dir(dir_name), symbol + '.csv')

    if os.path.isfile(timeseries_cache) and use_cache:
        pass
    else:
        ts = pdr.DataReader(symbol, 'yahoo', start=datetime.datetime(from_year, 1, 1))
        ts.to_csv(timeseries_cache, encoding='utf-8')

    ts = pd.read_csv(timeseries_cache, index_col='Date', parse_dates=True)
    ts = _adj_column_names(ts)
    return ts 
Example #29
Source File: QATest_None.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def test_data_reader(self):
        # PG = wb.DataReader('PG', data_source = 'quandl', start="1995-1-1")
        # head0 = PG.head()
        # tail0 = PG.tail()
        # print(head0)
        # print(tail0)
        pass 
Example #30
Source File: data_connection.py    From NowTrade with MIT License 5 votes vote down vote up
def get_data(self, symbol, start, end):
        """
        @type symbol: string
        @type start: datetime
        @type end: datetime
        @return: Returns a pandas DataFrame of the requested symbol
        @rtype: pandas.DataFrame
        """
        ret = web.DataReader(str(symbol).upper(), 'yahoo', start, end)
        ret.rename(columns=lambda name: '%s_%s' %(symbol, name), inplace=True)
        return ret