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


Python data.DataReader方法代码示例

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


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

示例1: test_yahoo

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_yahoo(self):
        # asserts that yahoo is minimally working and that it throws
        # an exception when DataReader can't get a 200 response from
        # yahoo
        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)

        self.assertEquals( web.DataReader("F", 'yahoo', start,
                                          end)['Close'][-1], 13.68) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_data.py

示例2: test_google

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_google(self):
        # asserts that google is minimally working and that it throws
        # an exception when DataReader can't get a 200 response from
        # google
        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)

        for locale in self.locales:
            with tm.set_locale(locale):
                panel = web.DataReader("F", 'google', start, end)
            self.assertEquals(panel.Close[-1], 13.68)

        self.assertRaises(Exception, web.DataReader, "NON EXISTENT TICKER",
                          'google', start, end) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:test_data.py

示例3: test_yahoo_fails

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_yahoo_fails(self):
        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)
        self.assertRaises(Exception, web.DataReader, "NON EXISTENT TICKER",
                          'yahoo', start, end) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_data.py

示例4: test_read_yahoo

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_read_yahoo(self):
        gs = DataReader("GS", "yahoo")
        assert isinstance(gs, DataFrame) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:test_data.py

示例5: test_read_google

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_read_google(self):
        gs = DataReader("GS", "google")
        assert isinstance(gs, DataFrame) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:test_data.py

示例6: test_read_famafrench

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_read_famafrench(self):
        for name in ("F-F_Research_Data_Factors",
                     "F-F_Research_Data_Factors_weekly", "6_Portfolios_2x3",
                     "F-F_ST_Reversal_Factor"):
            ff = DataReader(name, "famafrench")
            assert ff
            assert isinstance(ff, dict) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_data.py

示例7: test_fred

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_fred(self):

        # Throws an exception when DataReader can't get a 200 response from
        # FRED.

        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)

        received = web.DataReader("GDP", "fred", start, end)['GDP'].tail(1)[0]
        self.assertEquals(int(received), 16535)

        self.assertRaises(Exception, web.DataReader, "NON EXISTENT SERIES",
                          'fred', start, end) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:test_data.py

示例8: test_fred_nan

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_fred_nan(self):
        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)
        df = web.DataReader("DFII5", "fred", start, end)
        assert pd.isnull(df.ix['2010-01-01'][0]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_data.py

示例9: test_fred_multi

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_fred_multi(self):
        names = ['CPIAUCSL', 'CPALTT01USQ661S', 'CPILFESL']
        start = datetime(2010, 1, 1)
        end = datetime(2013, 1, 27)

        received = web.DataReader(names, "fred", start, end).head(1)
        expected = DataFrame([[217.478, 0.99701529, 220.544]], columns=names,
                             index=[pd.tslib.Timestamp('2010-01-01 00:00:00')])
        expected.index.rename('DATE', inplace=True)
        assert_frame_equal(received, expected, check_less_precise=True) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:test_data.py

示例10: test_fred_multi_bad_series

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def test_fred_multi_bad_series(self):

        names = ['NOTAREALSERIES', 'CPIAUCSL', "ALSO FAKE"]
        with tm.assertRaises(HTTPError):
            DataReader(names, data_source="fred") 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_data.py

示例11: start_market_simulation

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def start_market_simulation(self):
        data = web.DataReader(self.ticker, self.source,
                              self.start, self.end)

        for time, row in data.iterrows():
            self.md.add_last_price(time, self.ticker,
                                   row["Close"], row["Volume"])
            self.md.add_open_price(time, self.ticker, row["Open"])

            if not self.event_tick is None:
                self.event_tick(self.md) 
开发者ID:jamesmawm,项目名称:Mastering-Python-for-Finance-source-codes,代码行数:13,代码来源:B03898_09_01.py

示例12: create_plotly_candlestick

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def create_plotly_candlestick(symbol, start_date, end_date, filename=None):
    if filename is None:
        filename = os.path.join(CHARTS_DIR, '{}-{}-{}.html'.format(
            symbol, start_date.date(), end_date.date()))
    df = web.DataReader(symbol, 'yahoo', start_date, end_date)
    fig = FF.create_candlestick(df.Open, df.High, df.Low, df.Close, dates=df.index)
    plotly.offline.plot(fig, filename=filename)
    return filename 
开发者ID:zbarge,项目名称:stocklook,代码行数:10,代码来源:charts.py

示例13: _load_raw_yahoo_data

# 需要导入模块: from pandas.io import data [as 别名]
# 或者: from pandas.io.data import DataReader [as 别名]
def _load_raw_yahoo_data(indexes=None, stocks=None, start=None, end=None):
    """Load closing prices from yahoo finance.

    :Optional:
        indexes : dict (Default: {'SPX': '^GSPC'})
            Financial indexes to load.
        stocks : list (Default: ['AAPL', 'GE', 'IBM', 'MSFT',
                                 'XOM', 'AA', 'JNJ', 'PEP', 'KO'])
            Stock closing prices to load.
        start : datetime (Default: datetime(1993, 1, 1, 0, 0, 0, 0, pytz.utc))
            Retrieve prices from start date on.
        end : datetime (Default: datetime(2002, 1, 1, 0, 0, 0, 0, pytz.utc))
            Retrieve prices until end date.

    :Note:
        This is based on code presented in a talk by Wes McKinney:
        http://wesmckinney.com/files/20111017/notebook_output.pdf
    """
    assert indexes is not None or stocks is not None, """
must specify stocks or indexes"""

    if start is None:
        start = pd.datetime(1990, 1, 1, 0, 0, 0, 0, pytz.utc)

    if start is not None and end is not None:
        assert start < end, "start date is later than end date."

    data = OrderedDict()
    if stocks is not None:
        for stock in stocks:
            logger.info('Loading stock: {}'.format(stock))
            stock_pathsafe = stock.replace(os.path.sep, '--')
            cache_filename = "{stock}-{start}-{end}.csv".format(
                stock=stock_pathsafe,
                start=start,
                end=end).replace(':', '-')
            cache_filepath = get_cache_filepath(cache_filename)
            if os.path.exists(cache_filepath):
                stkd = pd.DataFrame.from_csv(cache_filepath)
            else:
                stkd = DataReader(stock, 'yahoo', start, end).sort_index()
                stkd.to_csv(cache_filepath)
            data[stock] = stkd

    if indexes is not None:
        for name, ticker in iteritems(indexes):
            logger.info('Loading index: {} ({})'.format(name, ticker))
            stkd = DataReader(ticker, 'yahoo', start, end).sort_index()
            data[name] = stkd

    return data 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:53,代码来源:loader.py


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