Skip to content

Commit b48e2e4

Browse files
authored
Merge pull request #812 from GreenArt11/master
MOEX: Use data from the main board only for each ticker
2 parents 54faf4f + 484f647 commit b48e2e4

File tree

7 files changed

+82
-15
lines changed

7 files changed

+82
-15
lines changed

docs/source/remote_data.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,19 @@ MOEX Data
680680
=========
681681
The Moscow Exchange (MOEX) provides historical data.
682682
683+
pandas_datareader.get_data_moex(*args) is equivalent to
684+
pandas_datareader.moex.MoexReader(*args).read()
683685
684686
.. ipython:: python
685687
686-
import pandas_datareader.data as web
687-
f = web.DataReader('USD000UTSTOM', 'moex', start='2017-07-01', end='2017-07-31')
688+
import pandas_datareader as pdr
689+
f = pdr.get_data_moex(['USD000UTSTOM', 'MAGN'], '2020-07-02', '2020-07-07')
690+
f.head()
691+
692+
f = pdr.moex.MoexReader('SBER', '2020-07-02', '2020-07-03').read()
693+
f.head()
694+
695+
f = pdr.moex.MoexReader('SBER', '2020-07-02', '2020-07-03').read_all_boards()
688696
f.head()
689697
690698
.. _remote_data.naver:

docs/source/whatsnew.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ What's New
1818

1919
These are new features and improvements of note in each release.
2020

21+
.. include:: whatsnew/v0.9.1.txt
2122
.. include:: whatsnew/v0.9.0.txt
2223
.. include:: whatsnew/v0.8.0.txt
2324
.. include:: whatsnew/v0.7.0.txt

docs/source/whatsnew/v.0.9.1.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.. _whatsnew_091:
2+
3+
v0.9.1 (July 26, 2020)
4+
---------------------------
5+
6+
Highlights include:
7+
8+
.. contents:: What's new in v0.9.1
9+
:local:
10+
:backlinks: none
11+
12+
.. _whatsnew_091.enhancements:
13+
14+
Enhancements
15+
~~~~~~~~~~~~
16+
17+
- MOEX now returns data only from primary trading boards for
18+
each ticker (:issue:`811`, :issue:`748`)
19+
- Added read_all_boards() method for MOEX that returns data
20+
from every trading board (ver. 0.9.0 behaviour)
21+
- Docs for MOEX reedited
22+
23+
.. _whatsnew_080.bug_fixes:
24+
25+
Bug Fixes
26+
~~~~~~~~~
27+
28+
- Fixed broken links on the github ussies on "What’s New" docs pages
29+
30+
Contributors
31+
~~~~~~~~~~~~
32+
- Dmitry Alekseev

docs/source/whatsnew/v0.7.0.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ Bug Fixes
7373
and currency pairs (:issue:`487`).
7474
- Add `is_list_like` to compatibility layer to avoid failure on pandas >= 0.23 (:issue:`520`).
7575
- Fixed Yahoo! time offset (:issue:`487`).
76-
- Fix Yahoo! quote reader (:issue: `540`).
77-
- Remove import of deprecated `tm.get_data_path` (:issue: `566`)
76+
- Fix Yahoo! quote reader (:issue:`540`).
77+
- Remove import of deprecated `tm.get_data_path` (:issue:`566`)
7878
- Allow full usage of stooq url parameters.
7979
- Removed unused requests-file and requests-ftp dependencies.
8080
- Fix Yahoo! actions issue where the default reporting adjusts dividends. The unadjusted
8181
dividends may lack precision due to accumulated numerical error when converting adjusted
82-
to the original dividend amount. (:issue: `495`)
82+
to the original dividend amount. (:issue:`495`)

docs/source/whatsnew/v0.8.0.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Enhancements
2626
~~~~~~~~~~~~
2727

2828
- Added Tiingo IEX Historical reader. (:issue:`619`)
29-
- Added support for Alpha Vantage intraday time series prices (:issue: `631`)
29+
- Added support for Alpha Vantage intraday time series prices (:issue:`631`)
3030
- Up to 15 years of historical prices from IEX with new platform, IEX Cloud
3131
- Added testing on Python 3.7 (:issue:`667`)
3232
- Allow IEX to read less than 1 year of data (:issue:`649`)
@@ -52,9 +52,9 @@ Bug Fixes
5252
~~~~~~~~~
5353

5454
- Fix Yahoo! actions issue where dividends are adjusted twice as a result of a
55-
change to the Yahoo! API. (:issue: `583`)
55+
change to the Yahoo! API. (:issue:`583`)
5656
- Fix AlphaVantage time series data ordering after provider switch to
57-
descending order (maintains ascending order for consistency). (:issue: `662`)
57+
descending order (maintains ascending order for consistency). (:issue:`662`)
5858
- Refactored compatibility library to be independent of pandas version.
5959
- Fixed quarter value handling in JSDMX and OECD. (:issue:`685`)
6060
- Fixed a bug in ``base`` so that the reader does not error when response.encoding

pandas_datareader/moex.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def _get_metadata(self):
102102
"""Get markets and engines for the given symbols"""
103103

104104
markets_n_engines = {}
105+
boards = {}
105106

106107
for symbol in self.symbols:
107108
response = self._get_response(self.__url_metadata.format(symbol=symbol))
@@ -130,6 +131,11 @@ def _get_metadata(self):
130131
markets_n_engines[symbol].append(
131132
(fields[5], fields[7])
132133
) # market and engine
134+
135+
if fields[14] == "1": # main board for symbol
136+
symbol_U = symbol.upper()
137+
boards[symbol_U] = fields[1]
138+
133139
if symbol not in markets_n_engines:
134140
raise IOError(
135141
"{} request returned no metadata: {}\n"
@@ -141,13 +147,14 @@ def _get_metadata(self):
141147
)
142148
if symbol in markets_n_engines:
143149
markets_n_engines[symbol] = list(set(markets_n_engines[symbol]))
144-
return markets_n_engines
150+
return markets_n_engines, boards
145151

146-
def read(self):
147-
"""Read data"""
152+
def read_all_boards(self):
153+
"""Read all data from every board for every ticker"""
148154

155+
markets_n_engines, boards = self._get_metadata()
149156
try:
150-
self.__markets_n_engines = self._get_metadata()
157+
self.__markets_n_engines = markets_n_engines
151158

152159
urls = self.url # generate urls per symbols
153160
dfs = [] # an array of pandas dataframes per symbol to concatenate
@@ -198,9 +205,21 @@ def read(self):
198205
"check URL or correct a date".format(self.__class__.__name__)
199206
)
200207
elif len(dfs) > 1:
201-
return concat(dfs, axis=0, join="outer", sort=True)
208+
b = concat(dfs, axis=0, join="outer", sort=True)
202209
else:
203-
return dfs[0]
210+
b = dfs[0]
211+
return b
212+
213+
def read(self):
214+
"""Read data from the primary board for each ticker"""
215+
markets_n_engines, boards = self._get_metadata()
216+
b = self.read_all_boards()
217+
result = pd.DataFrame()
218+
for secid in list(set(b["SECID"].tolist())):
219+
part = b[b["BOARDID"] == boards[secid]]
220+
result = result.append(part)
221+
result = result.drop_duplicates()
222+
return result
204223

205224
def _read_url_as_String(self, url, params=None):
206225
"""Open an url (and retry)"""

pandas_datareader/tests/test_moex.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def test_moex_stock_datareader(self):
2121
df = web.DataReader(
2222
["GAZP", "SIBN"], "moex", start="2019-12-26", end="2019-12-26"
2323
)
24-
assert df.size == 740
24+
assert df.size == 74
25+
except HTTPError as e:
26+
pytest.skip(e)
27+
28+
def test_moex_datareader_filter(self):
29+
try:
30+
df = web.DataReader("SBER", "moex", start="2020-07-14", end="2020-07-14")
31+
assert len(df) == 1
2532
except HTTPError as e:
2633
pytest.skip(e)

0 commit comments

Comments
 (0)