1
+ from datetime import datetime
1
2
from xml .etree import ElementTree
2
3
4
+ import numpy as np
3
5
from pandas import DataFrame , to_datetime
4
6
from pandas_datareader .base import _DailyBaseReader
5
7
@@ -47,7 +49,13 @@ def url(self):
47
49
return "https://fchart.stock.naver.com/sise.nhn"
48
50
49
51
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 }
51
59
return params
52
60
53
61
def _read_one_data (self , url , params ):
@@ -62,7 +70,8 @@ def _read_one_data(self, url, params):
62
70
)
63
71
prices ["Date" ] = to_datetime (prices ["Date" ])
64
72
65
- return prices
73
+ # NOTE: See _get_params() for explanations.
74
+ return prices [(prices ["Date" ] >= self .start ) & (prices ["Date" ] <= self .end )]
66
75
67
76
def _parse_xml_response (self , xml_content ):
68
77
"""Parses XML response from the server.
0 commit comments