1
1
import time
2
- from datetime import datetime , timedelta
2
+ from datetime import datetime
3
3
from warnings import warn
4
4
5
5
import requests
6
6
from pandas import DataFrame
7
7
8
8
from pandas_datareader ._utils import SymbolWarning
9
9
from pandas_datareader .base import _BaseReader
10
+ import pandas as pd
10
11
11
12
12
13
class MorningstarDailyReader (_BaseReader ):
@@ -149,13 +150,9 @@ def _dl_mult_symbols(self, symbols):
149
150
return dfx
150
151
151
152
@staticmethod
152
- def _convert_index2date (enddate , indexvals ):
153
- i = 0
154
- while i < len (indexvals ):
155
- days = indexvals [len (indexvals ) - 1 ] - indexvals [i ]
156
- d = enddate - timedelta (days = days )
157
- i += 1
158
- yield d .strftime ("%Y-%m-%d" )
153
+ def _convert_index2date (indexvals ):
154
+ base = pd .to_datetime ('1900-1-1' )
155
+ return [base + pd .to_timedelta (iv , unit = 'd' ) for iv in indexvals ]
159
156
160
157
def _restruct_json (self , symbol , jsondata ):
161
158
if jsondata is None :
@@ -166,11 +163,11 @@ def _restruct_json(self, symbol, jsondata):
166
163
dateidx = jsondata ["PriceDataList" ][0 ]["DateIndexs" ]
167
164
volumes = jsondata ["VolumeList" ]["Datapoints" ]
168
165
169
- date_ = self ._convert_index2date (enddate = self . end , indexvals = dateidx )
166
+ dates = self ._convert_index2date (indexvals = dateidx )
170
167
barss = []
171
168
for p in range (len (pricedata )):
172
169
bar = pricedata [p ]
173
- d = next ( date_ )
170
+ d = dates [ p ]
174
171
bardict = {
175
172
"Symbol" : symbol , "Date" : d , "Close" : bar [0 ], "High" : bar [1 ],
176
173
"Low" : bar [2 ], "Open" : bar [3 ]
@@ -180,8 +177,8 @@ def _restruct_json(self, symbol, jsondata):
180
177
else :
181
178
events = []
182
179
for x in divdata :
183
- delta = (datetime .strptime (x ["Date" ], "%Y-%m-%d" ) -
184
- datetime . strptime ( d , "%Y-%m-%d" ))
180
+ delta = (datetime .strptime (x ["Date" ], "%Y-%m-%d" )
181
+ - d . to_pydatetime ( ))
185
182
if delta .days == 0 :
186
183
events .append (x )
187
184
for e in events :
0 commit comments