Skip to content

Commit 7a4abda

Browse files
authored
Merge pull request #447 from bashtage/peijiche-stooq
Peijiche stooq
2 parents dbca479 + 9d7eaa6 commit 7a4abda

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

docs/source/remote_data.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Currently the following sources are supported:
3434
- :ref:`Eurostat<remote_data.eurostat>`
3535
- :ref:`Thrift Savings Plan<remote_data.tsp>`
3636
- :ref:`Nasdaq Trader symbol definitions<remote_data.nasdaq_symbols>`
37+
- :ref:`Stooq<remote_data.stooq>`
3738

3839
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.
3940

@@ -570,3 +571,16 @@ available. More information on the `field <http://www.nasdaqtrader.com/trader.as
570571
NASDAQ Symbol IBM
571572
NextShares False
572573
Name: IBM, dtype: object
574+
575+
576+
.. _remote_data.stooq:
577+
578+
Stooq Index Data
579+
================
580+
Google finance doesn't provide common index data download. The Stooq site has the data for download.
581+
582+
.. ipython:: python
583+
584+
import pandas_datareader.data as web
585+
f = web.DataReader("^DJI", 'stooq')
586+
f[:10]

pandas_datareader/data.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas_datareader.nasdaq_trader import get_nasdaq_symbols
1818
from pandas_datareader.oecd import OECDReader
1919
from pandas_datareader.quandl import QuandlReader
20+
from pandas_datareader.stooq import StooqDailyReader
2021
from pandas_datareader.yahoo.actions import (YahooActionReader, YahooDivReader)
2122
from pandas_datareader.yahoo.components import _get_data as \
2223
get_components_yahoo
@@ -27,7 +28,8 @@
2728
__all__ = ['get_components_yahoo', 'get_data_enigma', 'get_data_famafrench',
2829
'get_data_fred', 'get_data_google', 'get_data_moex',
2930
'get_data_quandl', 'get_data_yahoo', 'get_data_yahoo_actions',
30-
'get_nasdaq_symbols', 'get_quote_google', 'get_quote_yahoo']
31+
'get_nasdaq_symbols', 'get_quote_google', 'get_quote_yahoo',
32+
'get_data_stooq', 'DataReader']
3133

3234

3335
def get_data_fred(*args, **kwargs):
@@ -70,6 +72,10 @@ def get_data_moex(*args, **kwargs):
7072
return MoexReader(*args, **kwargs).read()
7173

7274

75+
def get_data_stooq(*args, **kwargs):
76+
return StooqDailyReader(*args, **kwargs).read()
77+
78+
7379
def DataReader(name, data_source=None, start=None, end=None,
7480
retry_count=3, pause=0.001, session=None, access_key=None):
7581
"""
@@ -150,6 +156,11 @@ def DataReader(name, data_source=None, start=None, end=None,
150156
return BankOfCanadaReader(symbols=name, start=start, end=end,
151157
retry_count=retry_count, pause=pause,
152158
session=session).read()
159+
elif data_source == "stooq":
160+
return StooqDailyReader(symbols=name,
161+
chunksize=25,
162+
retry_count=retry_count, pause=pause,
163+
session=session).read()
153164

154165
elif data_source == "enigma":
155166
return EnigmaReader(dataset_id=name, api_key=access_key).read()

pandas_datareader/stooq.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pandas_datareader.base import _DailyBaseReader
2+
3+
4+
class StooqDailyReader(_DailyBaseReader):
5+
6+
"""
7+
Returns DataFrame/Panel of historical stock prices from symbols, over date
8+
range, start to end. To avoid being penalized by Google Finance servers,
9+
pauses between downloading 'chunks' of symbols can be specified.
10+
11+
Parameters
12+
----------
13+
symbols : string, array-like object (list, tuple, Series), or DataFrame
14+
Single stock symbol (ticker), array-like object of symbols or
15+
DataFrame with index containing stock symbols.
16+
retry_count : int, default 3
17+
Number of times to retry query request.
18+
pause : int, default 0
19+
Time, in seconds, to pause between consecutive queries of chunks. If
20+
single value given for symbol, represents the pause between retries.
21+
chunksize : int, default 25
22+
Number of symbols to download consecutively before intiating pause.
23+
session : Session, default None
24+
requests.sessions.Session instance to be used
25+
"""
26+
27+
@property
28+
def url(self):
29+
return 'https://stooq.com/q/d/l/'
30+
31+
def _get_params(self, symbol):
32+
params = {
33+
's': symbol,
34+
'i': "d"
35+
}
36+
return params

pandas_datareader/tests/test_stooq.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pandas_datareader.data as web
2+
from pandas_datareader.data import get_data_stooq
3+
4+
5+
def test_stooq_dji():
6+
f = web.DataReader('^DJI', 'stooq')
7+
assert f.shape[0] > 0
8+
9+
10+
def test_get_data_stooq_dji():
11+
f = get_data_stooq('^DAX')
12+
assert f.shape[0] > 0

0 commit comments

Comments
 (0)