Skip to content

Peijiche stooq #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/source/remote_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Currently the following sources are supported:
- :ref:`Eurostat<remote_data.eurostat>`
- :ref:`Thrift Savings Plan<remote_data.tsp>`
- :ref:`Nasdaq Trader symbol definitions<remote_data.nasdaq_symbols>`
- :ref:`Stooq<remote_data.stooq>`

It should be noted, that various sources support different kinds of data, so not all sources implement the same methods and the data elements returned might also differ.

Expand Down Expand Up @@ -570,3 +571,16 @@ available. More information on the `field <http://www.nasdaqtrader.com/trader.as
NASDAQ Symbol IBM
NextShares False
Name: IBM, dtype: object


.. _remote_data.stooq:

Stooq Index Data
================
Google finance doesn't provide common index data download. The Stooq site has the data for download.

.. ipython:: python

import pandas_datareader.data as web
f = web.DataReader("^DJI", 'stooq')
f[:10]
13 changes: 12 additions & 1 deletion pandas_datareader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from pandas_datareader.nasdaq_trader import get_nasdaq_symbols
from pandas_datareader.oecd import OECDReader
from pandas_datareader.quandl import QuandlReader
from pandas_datareader.stooq import StooqDailyReader
from pandas_datareader.yahoo.actions import (YahooActionReader, YahooDivReader)
from pandas_datareader.yahoo.components import _get_data as \
get_components_yahoo
Expand All @@ -27,7 +28,8 @@
__all__ = ['get_components_yahoo', 'get_data_enigma', 'get_data_famafrench',
'get_data_fred', 'get_data_google', 'get_data_moex',
'get_data_quandl', 'get_data_yahoo', 'get_data_yahoo_actions',
'get_nasdaq_symbols', 'get_quote_google', 'get_quote_yahoo']
'get_nasdaq_symbols', 'get_quote_google', 'get_quote_yahoo',
'get_data_stooq', 'DataReader']


def get_data_fred(*args, **kwargs):
Expand Down Expand Up @@ -70,6 +72,10 @@ def get_data_moex(*args, **kwargs):
return MoexReader(*args, **kwargs).read()


def get_data_stooq(*args, **kwargs):
return StooqDailyReader(*args, **kwargs).read()


def DataReader(name, data_source=None, start=None, end=None,
retry_count=3, pause=0.001, session=None, access_key=None):
"""
Expand Down Expand Up @@ -150,6 +156,11 @@ def DataReader(name, data_source=None, start=None, end=None,
return BankOfCanadaReader(symbols=name, start=start, end=end,
retry_count=retry_count, pause=pause,
session=session).read()
elif data_source == "stooq":
return StooqDailyReader(symbols=name,
chunksize=25,
retry_count=retry_count, pause=pause,
session=session).read()

elif data_source == "enigma":
return EnigmaReader(dataset_id=name, api_key=access_key).read()
Expand Down
36 changes: 36 additions & 0 deletions pandas_datareader/stooq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pandas_datareader.base import _DailyBaseReader


class StooqDailyReader(_DailyBaseReader):

"""
Returns DataFrame/Panel of historical stock prices from symbols, over date
range, start to end. To avoid being penalized by Google Finance servers,
pauses between downloading 'chunks' of symbols can be specified.

Parameters
----------
symbols : string, array-like object (list, tuple, Series), or DataFrame
Single stock symbol (ticker), array-like object of symbols or
DataFrame with index containing stock symbols.
retry_count : int, default 3
Number of times to retry query request.
pause : int, default 0
Time, in seconds, to pause between consecutive queries of chunks. If
single value given for symbol, represents the pause between retries.
chunksize : int, default 25
Number of symbols to download consecutively before intiating pause.
session : Session, default None
requests.sessions.Session instance to be used
"""

@property
def url(self):
return 'https://stooq.com/q/d/l/'

def _get_params(self, symbol):
params = {
's': symbol,
'i': "d"
}
return params
12 changes: 12 additions & 0 deletions pandas_datareader/tests/test_stooq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pandas_datareader.data as web
from pandas_datareader.data import get_data_stooq


def test_stooq_dji():
f = web.DataReader('^DJI', 'stooq')
assert f.shape[0] > 0


def test_get_data_stooq_dji():
f = get_data_stooq('^DAX')
assert f.shape[0] > 0