Skip to content

Commit

Permalink
0.9.30 update
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Oct 5, 2023
1 parent e0b44f3 commit cbee08d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions czsc/utils/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@
"""
import pandas as pd
from pathlib import Path
from datetime import datetime


calendar = pd.read_feather(Path(__file__).parent / "china_calendar.feather")


def is_trading_date(date):
def is_trading_date(date=datetime.now()):
"""判断是否是交易日"""
date = pd.to_datetime(date)
is_open = calendar[calendar['cal_date'] == date].iloc[0]['is_open']
return is_open == 1


def next_trading_date(date, n=1):
def next_trading_date(date=datetime.now(), n=1):
"""获取未来第N个交易日"""
date = pd.to_datetime(date)
df = calendar[calendar['cal_date'] > date]
return df[df['is_open'] == 1].iloc[n - 1]['cal_date']


def prev_trading_date(date, n=1):
def prev_trading_date(date=datetime.now(), n=1):
"""获取过去第N个交易日"""
date = pd.to_datetime(date)
df = calendar[calendar['cal_date'] < date]
return df[df['is_open'] == 1].iloc[-n]['cal_date']


def get_trading_dates(sdt, edt):
def get_trading_dates(sdt, edt=datetime.now()):
"""获取两个日期之间的所有交易日"""
sdt = pd.to_datetime(sdt)
edt = pd.to_datetime(edt)
sdt, edt = pd.to_datetime(sdt), pd.to_datetime(edt)
df = calendar[(calendar['cal_date'] >= sdt) & (calendar['cal_date'] <= edt)]
return df[df['is_open'] == 1]['cal_date'].tolist()

0 comments on commit cbee08d

Please sign in to comment.