forked from waditu/czsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
113 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
author: zengbin93 | ||
email: [email protected] | ||
create_dt: 2023/3/29 10:04 | ||
describe: | ||
describe: | ||
""" | ||
import re | ||
from loguru import logger | ||
|
@@ -61,7 +61,7 @@ def parse_params(self, name, signal): | |
return None | ||
|
||
try: | ||
params = parse(pats, key).named # type: ignore | ||
params = parse(pats, key).named # type: ignore | ||
if 'di' in params: | ||
params['di'] = int(params['di']) | ||
|
||
|
@@ -140,4 +140,3 @@ def get_signals_freqs(signals_seq: List) -> List[str]: | |
if _freqs: | ||
freqs.extend(_freqs) | ||
return [x for x in sorted_freqs if x in freqs] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
author: zengbin93 | ||
email: [email protected] | ||
create_dt: 2023/9/10 17:53 | ||
describe: A股+期货的交易日历 | ||
""" | ||
import pandas as pd | ||
from pathlib import Path | ||
|
||
|
||
def __prepare_cal(): | ||
"""使用tushare获取交易日历,保存到本地""" | ||
import pandas as pd | ||
import tushare as ts | ||
|
||
pro = ts.pro_api() | ||
exchanges = ['SSE', 'SZSE', 'CFFEX', 'SHFE', 'CZCE', 'DCE', 'INE'] | ||
res = [] | ||
for exchange in exchanges: | ||
df = pro.trade_cal(exchange=exchange, start_date='20100101', end_date='20251231') | ||
res.append(df) | ||
df = pd.concat(res, ignore_index=True) | ||
df['is_open'] = df['is_open'].astype(int) | ||
dfc = pd.pivot_table(df, index='cal_date', columns='exchange', values='is_open').fillna(0).reset_index() | ||
dfc['cal_date'] = pd.to_datetime(dfc['cal_date']) | ||
dfc.to_feather('calendar.feather') | ||
|
||
# 验证:是不是所有交易所的交易日都一样 | ||
dfc = dfc[dfc['cal_date'] >= '2021-01-01'] | ||
dfc['sum'] = dfc[exchanges].sum(axis=1) | ||
assert dfc['sum'].value_counts() | ||
|
||
# 所有国内交易所的交易日历都是一样的 | ||
df = pro.trade_cal(exchange="SSE", start_date='20100101', end_date='20251231') | ||
df['cal_date'] = pd.to_datetime(df['cal_date']) | ||
df.sort_values('cal_date', inplace=True, ascending=True) | ||
df = df.reset_index(drop=True) | ||
df[['cal_date', 'is_open']].to_feather('china_calendar.feather') | ||
|
||
|
||
calendar = pd.read_feather(Path(__file__).parent / "china_calendar.feather") | ||
|
||
|
||
def is_trading_date(date): | ||
"""判断是否是交易日""" | ||
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): | ||
"""获取未来第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): | ||
"""获取过去第N个交易日""" | ||
date = pd.to_datetime(date) | ||
df = calendar[calendar['cal_date'] <= date] | ||
return df[df['is_open'] == 1].iloc[-n]['cal_date'] |
Binary file not shown.
Oops, something went wrong.