Skip to content

Commit

Permalink
采样更新: 增加tb/快期的采样模式
Browse files Browse the repository at this point in the history
采样更新:  增加tb/快期的采样模式
  • Loading branch information
yutiansut authored Aug 13, 2019
2 parents b8ad1c1 + f1bed59 commit 0730d1c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions QUANTAXIS/QAData/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
QA_data_ctptick_resample, QA_data_day_resample,
QA_data_futuremin_resample_series,
QA_data_futuremin_resample, QA_data_tick_resample,
QA_data_futuremin_resample_tb_kq,
QA_data_tick_resample_1min)
from QUANTAXIS.QAData.dsmethods import (QDS_IndexDayWarpper,
QDS_IndexMinWarpper,
Expand Down
38 changes: 36 additions & 2 deletions QUANTAXIS/QAData/data_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,41 @@ def QA_data_futuremin_resample(min_data, type_='5min', exchange_id=EXCHANGE_ID.S
closed='right',
loffset=type_
).agg(CONVERSION)
return pd.concat([part_1_res, part_2_res]).dropna().sort_index().reset_index().set_index(['datetime', 'code'])
part_3 = min_data.iloc[idx.indexer_between_time('21:00', '23:59')]
part_3_res = part_3.resample(
type_,
base=0,
closed='right',
loffset=type_
).agg(CONVERSION)
return pd.concat([part_1_res, part_2_res, part_3_res]).dropna().sort_index().reset_index().set_index(['datetime', 'code'])


def QA_data_futuremin_resample_tb_kq(min_data, type_='5min', exchange_id=EXCHANGE_ID.SHFE):
"""期货分钟线采样成大周期
此采样方法仅适用于tb/快期, 因此单独拿出来
分钟线采样成子级别的分钟线
"""
CONVERSION = {
'code': 'first',
'open': 'first',
'high': 'max',
'low': 'min',
'close': 'last',
'tradetime': 'last',
'position': 'last',
'volume': 'sum'}
min_data = min_data.loc[:, list(CONVERSION.keys())]
return min_data.resample(
type_,
base=0,
closed='right',
loffset=type_
).agg(CONVERSION).dropna().sort_index().reset_index().set_index(['datetime', 'code'])


def QA_data_futuremin_resample_today(min_data, type_='1D', exchange_id=EXCHANGE_ID.SHFE):
Expand Down Expand Up @@ -680,7 +714,7 @@ def QA_data_day_resample(day_data, type_='w'):
type_,
closed='right'
).apply(CONVERSION).dropna()
return data.assign(date=pd.to_datetime(data.date)).set_index(['date','code'])
return data.assign(date=pd.to_datetime(data.date)).set_index(['date', 'code'])


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion QUANTAXIS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
2017/4/8
"""

__version__ = '1.5.8'
__version__ = '1.5.9'
__author__ = 'yutiansut'

import argparse
Expand Down Expand Up @@ -63,6 +63,7 @@
QA_data_tick_resample_1min,
QA_data_futuremin_resample_series,
QA_data_futuremin_resample,
QA_data_futuremin_resample_tb_kq,
QA_DataStruct_Day,
QA_DataStruct_Financial,
QA_DataStruct_Future_day,
Expand Down

0 comments on commit 0730d1c

Please sign in to comment.