From d1ee105e2baef36e3e7b5e1596bc48e469001af3 Mon Sep 17 00:00:00 2001 From: yutiansut Date: Tue, 13 Aug 2019 15:56:14 +0800 Subject: [PATCH] =?UTF-8?q?#update=20tb/=E5=BF=AB=E6=9C=9F=E7=9A=84?= =?UTF-8?q?=E9=87=87=E6=A0=B7=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QUANTAXIS/QAData/__init__.py | 1 + QUANTAXIS/QAData/data_resample.py | 27 +++++++++++++++++++++++++++ QUANTAXIS/__init__.py | 1 + 3 files changed, 29 insertions(+) diff --git a/QUANTAXIS/QAData/__init__.py b/QUANTAXIS/QAData/__init__.py index 005904e05..0fd318613 100755 --- a/QUANTAXIS/QAData/__init__.py +++ b/QUANTAXIS/QAData/__init__.py @@ -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, diff --git a/QUANTAXIS/QAData/data_resample.py b/QUANTAXIS/QAData/data_resample.py index 634685258..924c99eb3 100755 --- a/QUANTAXIS/QAData/data_resample.py +++ b/QUANTAXIS/QAData/data_resample.py @@ -545,6 +545,33 @@ def QA_data_futuremin_resample(min_data, type_='5min', exchange_id=EXCHANGE_ID.S 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): """期货分钟线采样成大周期 diff --git a/QUANTAXIS/__init__.py b/QUANTAXIS/__init__.py index 6fcaaf77b..2f7312d1a 100755 --- a/QUANTAXIS/__init__.py +++ b/QUANTAXIS/__init__.py @@ -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,