def get_nearest_business_day_in_a_week(): curr = datetime.datetime.now() prev = curr - datetime.timedelta(days=7) curr = _datetime2string(curr) prev = _datetime2string(prev) df = krx.get_index_ohlcv_by_date(prev, curr, "1001") return df.index[-1].strftime("%Y%m%d")
def get_index_ohlcv_by_date(fromdate, todate, ticker, freq='d', name_display=False): """인덱스 OHLCV 조회 :param fromdate: 조회 시작 일자 (YYYYMMDD) :param todate : 조회 종료 일자 (YYYYMMDD) :param ticker : 조회할 지표의 티커 :param freq : d - 일 / m - 월 / y - 년 :param name_display : columns의 이름 출력 여부 (True/False) :return: """ if isinstance(fromdate, datetime.datetime): fromdate = _datetime2string(fromdate, freq) if isinstance(todate, datetime.datetime): todate = _datetime2string(todate) df = krx.get_index_ohlcv_by_date(fromdate, todate, ticker) if name_display: df.columns.name = get_index_ticker_name(ticker) how = {'시가': 'first', '고가': 'max', '저가': 'min', '종가': 'last', '거래량': 'sum'} return resample_ohlcv(df, freq, how)
def get_recent_business_day(): curr = datetime.datetime.now() prev = curr - datetime.timedelta(days=7) curr = _datetime2string(curr) prev = _datetime2string(prev) df = krx.get_index_ohlcv_by_date(prev, curr, "001", "KOSPI") return df.index[-1].strftime("%Y%m%d")
def _get_index_ohlcv_by_date(fromdate, todate, ticker, market, freq): """ :param fromdate: 조회 시작 일자 (YYYYMMDD) :param todate : 조회 종료 일자 (YYYYMMDD) :param ticker : 조회할 지표의 티커 :param market : KOSPI / KOSDAQ :param freq : d - 일 / m - 월 / y - 년 :return: """ id = krx.IndexTicker().get_id(fromdate, market, ticker) df = krx.get_index_ohlcv_by_date(fromdate, todate, id, market) how = {'시가': 'first', '고가': 'max', '저가': 'min', '종가': 'last', '거래량': 'sum'} return resample_ohlcv(df, freq, how)