当前位置: 首页>>代码示例>>Python>>正文


Python data.DataReader方法代码示例

本文整理汇总了Python中pandas_datareader.data.DataReader方法的典型用法代码示例。如果您正苦于以下问题:Python data.DataReader方法的具体用法?Python data.DataReader怎么用?Python data.DataReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas_datareader.data的用法示例。


在下文中一共展示了data.DataReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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') 
开发者ID:enigmampc,项目名称:catalyst,代码行数:27,代码来源:generate.py

示例2: get_ticker_data

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:stefmolin,项目名称:stock-analysis,代码行数:22,代码来源:stock_reader.py

示例3: get_fama_french

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:quantopian,项目名称:empyrical,代码行数:23,代码来源:utils.py

示例4: get_data_from_yahoo

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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)) 
开发者ID:furas,项目名称:python-examples,代码行数:27,代码来源:main.py

示例5: download_stock

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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)) 
开发者ID:CNuge,项目名称:kaggle-code,代码行数:13,代码来源:getSandP.py

示例6: _download_web

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
def _download_web(name, **kwargs):
    """
    Thin wrapper to enable memoization
    """
    return pdata.DataReader(name, **kwargs) 
开发者ID:pmorissette,项目名称:ffn,代码行数:7,代码来源:data.py

示例7: fetch_timeseries

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:fja05680,项目名称:pinkfish,代码行数:29,代码来源:fetch.py

示例8: test_data_reader

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:9,代码来源:QATest_None.py

示例9: get_data

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:edouardpoitras,项目名称:NowTrade,代码行数:13,代码来源:data_connection.py

示例10: DataReader

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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) 
开发者ID:sinhrks,项目名称:japandas,代码行数:11,代码来源:data.py

示例11: pushButtonClicked

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
def pushButtonClicked(self):
        code = self.lineEdit.text()
        df = web.DataReader(code, "yahoo")
        df['MA20'] = df['Adj Close'].rolling(window=20).mean()
        df['MA60'] = df['Adj Close'].rolling(window=60).mean()

        ax = self.fig.add_subplot(111)
        ax.plot(df.index, df['Adj Close'], label='Adj Close')
        ax.plot(df.index, df['MA20'], label='MA20')
        ax.plot(df.index, df['MA60'], label='MA60')
        ax.legend(loc='upper right')
        ax.grid()

        self.canvas.draw() 
开发者ID:pystockhub,项目名称:book,代码行数:16,代码来源:26.py

示例12: load

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
def load(symbol, provider='yahoo', start=datetime(2010, 1, 1), end=None):
    # TODO: Improve Error Handling
    try:
        data = web.DataReader(symbol, data_source=provider,
                              start=start, end=end)
    except:
        raise ValueError('Symbol not found!')

    if data is None:
        raise ValueError('No data found! Could be a wrong provider.')
    return data 
开发者ID:tuinvest,项目名称:pytrading,代码行数:13,代码来源:dataprovider.py

示例13: load_financial_data

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:PacktPublishing,项目名称:Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading,代码行数:11,代码来源:ch4_pairs_correlation_real_symbol.py

示例14: load_financial_data

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:PacktPublishing,项目名称:Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading,代码行数:11,代码来源:ch4_turtle_trading.py

示例15: load_financial_data

# 需要导入模块: from pandas_datareader import data [as 别名]
# 或者: from pandas_datareader.data import DataReader [as 别名]
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 
开发者ID:PacktPublishing,项目名称:Learn-Algorithmic-Trading---Fundamentals-of-Algorithmic-Trading,代码行数:11,代码来源:lr.py


注:本文中的pandas_datareader.data.DataReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。