Skip to content

Commit

Permalink
0.9.31 update
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Oct 9, 2023
1 parent aedb0a1 commit 80e6461
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
11 changes: 2 additions & 9 deletions czsc/utils/bar_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def check_freq_and_market(time_seq: List[AnyStr], freq: Optional[AnyStr] = None)
time_seq = sorted(list(set(time_seq)))
assert len(time_seq) >= 2, "time_seq长度必须大于等于2"

res = {}
for key, tts in freq_market_times.items():
if freq and not key.startswith(freq):
continue
Expand All @@ -65,13 +64,7 @@ def check_freq_and_market(time_seq: List[AnyStr], freq: Optional[AnyStr] = None)
freq_x, market = key.split("_")
return freq_x, market

# 原则上,交易时间序列必须包含交易时间段的 70% ~ 120%,否则认为不是同一周期
if len(time_seq) < len(tts) * 0.7 or len(time_seq) > len(tts) * 1.2:
continue

res[key] = len(set(time_seq).intersection(set(tts))) / len(tts)
freq_x, market = sorted(res.items(), key=lambda x: x[1], reverse=True)[0][0].split("_")
return freq_x, market
return None, "默认"


def freq_end_date(dt, freq: Union[Freq, AnyStr]):
Expand Down Expand Up @@ -135,7 +128,7 @@ def freq_end_time(dt: datetime, freq: Union[Freq, AnyStr], market="A股") -> dat
return edt

if not ("15:00" > hm > "09:00") and market == "期货":
dt = next_trading_date(dt.strftime("%Y-%m-%d"), 1)
dt = next_trading_date(dt, n=1)

return freq_end_date(dt.date(), freq)

Expand Down
17 changes: 14 additions & 3 deletions examples/test_offline/test_resample_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
from czsc.connectors.research import get_raw_bars


def test_split():
from czsc.utils.bar_generator import *
row = mss[(mss['market'] == '期货') & (mss['time'] == '00:00')]
def test_read():
bars = get_raw_bars(symbol='SQrb9001', sdt='20170101', edt='20230101', freq='日线')
bars = get_raw_bars(symbol='SQrb9001', sdt='20170101', edt='20230101', freq='5分钟')


def test_check_freq_and_market():
from czsc.utils.bar_generator import check_freq_and_market
gruop_name = "期货主力"
# gruop_name = "中证500成分股"
files = Path(fr"D:\CZSC投研数据\{gruop_name}").glob("*.parquet")
for file in files:
df = pd.read_parquet(file)
time_seq = sorted(list({x.strftime("%H:%M") for x in df['dt']}))
x_freq, market = check_freq_and_market(time_seq=time_seq)
print(file.stem, x_freq, market)


def get_future_times():
files = Path(r"D:\CZSC投研数据\期货主力").glob("*.parquet")
Expand Down

0 comments on commit 80e6461

Please sign in to comment.