Skip to content

Commit

Permalink
0.9.47 fix minites split
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Apr 2, 2024
1 parent 77dc4fe commit 8f87a02
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
36 changes: 11 additions & 25 deletions czsc/utils/bar_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,39 +81,25 @@ def check_freq_and_market(time_seq: List[AnyStr], freq: Optional[AnyStr] = None)
- freq K线周期
- market 交易市场
"""
if not freq or freq in ['日线', '周线', '月线', '季线', '年线']:
if freq in ['日线', '周线', '月线', '季线', '年线']:
return freq, "默认"

# if freq == '1分钟':
# time_seq.extend(['14:57', '14:58', '14:59', '15:00'])
if freq == '1分钟':
time_seq.extend(['14:57', '14:58', '14:59', '15:00'])

time_seq = sorted(list(set(time_seq)))
assert len(time_seq) >= 2, "time_seq长度必须大于等于2"

a_sdt = freq_market_times[f"{freq}_A股"][0]
f_sdt = freq_market_times[f"{freq}_期货"][0]
for key, tts in freq_market_times.items():
if freq and not key.startswith(freq):
continue

# 判断是不是有 dt 落在 10:15 - 10:30 之间
# match = [x for x in time_seq if "10:15" < x < "10:30"]
sub_tts = [x for x in tts if x >= min(time_seq) and x <= max(time_seq)]
if set(time_seq) == set(sub_tts):
freq_x, market = key.split("_")
return freq_x, market

if time_seq[0] >= a_sdt and time_seq[-1] <= "15:00":
market = "A股"
elif time_seq[0] >= f_sdt and time_seq[-1] in ["15:00", "23:00", "23:30", "02:30"]:
market = "期货"
else:
market = "默认"

return freq, market

# for key, tts in freq_market_times.items():
# if freq and not key.startswith(freq):
# continue

# if set(time_seq) == set(tts[:len(time_seq)]):
# freq_x, market = key.split("_")
# return freq_x, market

# return None, "默认"
return None, "默认"


def freq_end_date(dt, freq: Union[Freq, AnyStr]):
Expand Down
Binary file modified czsc/utils/minites_split.feather
Binary file not shown.
14 changes: 14 additions & 0 deletions examples/develop/minites_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pandas as pd

df = pd.read_feather(r"D:\ZB\git_repo\waditu\czsc\czsc\utils\minites_split.feather")
df.to_csv(r"C:\Users\zengb\Desktop\minites_split.csv", index=False, encoding="gbk")

# df = pd.read_feather(r"C:\Users\zengb\Desktop\minites_split_240317.feather")

df = pd.read_csv(r"C:\Users\zengb\Desktop\minites_split.csv", encoding="gbk")
# df.to_excel(r"C:\Users\zengb\Desktop\minites_split.xlsx", index=False)
cols = [x for x in df.columns if x not in ["market"]]
for col in cols:
df[col] = pd.to_datetime(df[col]).dt.strftime("%H:%M")

df.to_feather(r"D:\ZB\git_repo\waditu\czsc\czsc\utils\minites_split.feather")
7 changes: 4 additions & 3 deletions test/test_bar_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def test_check_freq_and_market():
time_seq = ['11:00', '15:00', '23:00', '01:00', '02:30']
assert check_freq_and_market(time_seq) == ('120分钟', '期货')
assert check_freq_and_market(time_seq, freq='120分钟') == ('120分钟', '期货')

time_seq = [
'09:31',
Expand Down Expand Up @@ -257,8 +257,9 @@ def test_check_freq_and_market():
]
assert check_freq_and_market(time_seq, freq='1分钟') == ('1分钟', 'A股')

for key, values in freq_market_times.items():
assert check_freq_and_market(values) == (key.split("_")[0], key.split("_")[1])
for key, time_seq in freq_market_times.items():
freq, market = key.split("_")
assert check_freq_and_market(time_seq, freq) == (freq, market)


def test_freq_end_time():
Expand Down

0 comments on commit 8f87a02

Please sign in to comment.