當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。