1+ from datetime import datetime
12from xml .etree import ElementTree
23
4+ import numpy as np
35from pandas import DataFrame , to_datetime
46from pandas_datareader .base import _DailyBaseReader
57
@@ -47,7 +49,13 @@ def url(self):
4749 return "https://fchart.stock.naver.com/sise.nhn"
4850
4951 def _get_params (self , symbol ):
50- params = {"symbol" : symbol , "timeframe" : "day" , "count" : 500 , "requestType" : 0 }
52+ # NOTE: The server does not take start, end dates as inputs; it only
53+ # takes the number of past days as an input. To circumvent this
54+ # pitfall, we calculate the number of business days between self.start
55+ # and the current date. And then before returning the final result
56+ # (from _read_one_data()) we filter by self.end.
57+ days = np .busday_count (self .start .date (), datetime .now ().date ())
58+ params = {"symbol" : symbol , "timeframe" : "day" , "count" : days , "requestType" : 0 }
5159 return params
5260
5361 def _read_one_data (self , url , params ):
@@ -62,7 +70,8 @@ def _read_one_data(self, url, params):
6270 )
6371 prices ["Date" ] = to_datetime (prices ["Date" ])
6472
65- return prices
73+ # NOTE: See _get_params() for explanations.
74+ return prices [(prices ["Date" ] >= self .start ) & (prices ["Date" ] <= self .end )]
6675
6776 def _parse_xml_response (self , xml_content ):
6877 """Parses XML response from the server.
0 commit comments