From 654fe3ae8d522b7bf11cbf4f92342c289b643206 Mon Sep 17 00:00:00 2001 From: yutiansut Date: Mon, 7 Jan 2019 05:22:22 +0800 Subject: [PATCH 1/3] # --- QUANTAXIS/QAData/data_resample.py | 98 ++++++++++++++++++------------- QUANTAXIS/QAUtil/QADate_trade.py | 2 +- 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/QUANTAXIS/QAData/data_resample.py b/QUANTAXIS/QAData/data_resample.py index 91489735b..d33b278ea 100755 --- a/QUANTAXIS/QAData/data_resample.py +++ b/QUANTAXIS/QAData/data_resample.py @@ -26,8 +26,8 @@ import pandas as pd -def QA_data_tick_resample_1min(tick, type_='1min', if_drop=True): +def QA_data_tick_resample_1min(tick, type_='1min', if_drop=True): """ tick 采样为 分钟数据 1. 仅使用将 tick 采样为 1 分钟数据 @@ -52,36 +52,50 @@ def QA_data_tick_resample_1min(tick, type_='1min', if_drop=True): # do fix on the first and last bar # 某些股票某些日期没有集合竞价信息,譬如 002468 在 2017 年 6 月 5 日的数据 if len(_data.loc[time(9, 25): time(9, 25)]) > 0: - _data1.loc[time(9, 31): time(9, 31), 'open'] = _data1.loc[time(9, 26): time(9, 26), 'open'].values - _data1.loc[time(9, 31): time(9, 31), 'high'] = _data1.loc[time(9, 26): time(9, 31), 'high'].max() - _data1.loc[time(9, 31): time(9, 31), 'low'] = _data1.loc[time(9, 26): time(9, 31), 'low'].min() - _data1.loc[time(9, 31): time(9, 31), 'vol'] = _data1.loc[time(9, 26): time(9, 31), 'vol'].sum() - _data1.loc[time(9, 31): time(9, 31), 'amount'] = _data1.loc[time(9, 26): time(9, 31), 'amount'].sum() + _data1.loc[time(9, 31): time(9, 31), 'open'] = _data1.loc[time( + 9, 26): time(9, 26), 'open'].values + _data1.loc[time(9, 31): time(9, 31), 'high'] = _data1.loc[time( + 9, 26): time(9, 31), 'high'].max() + _data1.loc[time(9, 31): time(9, 31), 'low'] = _data1.loc[time( + 9, 26): time(9, 31), 'low'].min() + _data1.loc[time(9, 31): time(9, 31), 'vol'] = _data1.loc[time( + 9, 26): time(9, 31), 'vol'].sum() + _data1.loc[time(9, 31): time(9, 31), 'amount'] = _data1.loc[time( + 9, 26): time(9, 31), 'amount'].sum() # 通达信分笔数据有的有 11:30 数据,有的没有 if len(_data.loc[time(11, 30): time(11, 30)]) > 0: - _data1.loc[time(11, 30): time(11, 30), 'high'] = _data1.loc[time(11, 30): time(11, 31), 'high'].max() - _data1.loc[time(11, 30): time(11, 30), 'low'] = _data1.loc[time(11, 30): time(11, 31), 'low'].min() - _data1.loc[time(11, 30): time(11, 30), 'close'] = _data1.loc[time(11, 31): time(11, 31), 'close'].values - _data1.loc[time(11, 30): time(11, 30), 'vol'] = _data1.loc[time(11, 30): time(11, 31), 'vol'].sum() - _data1.loc[time(11, 30): time(11, 30), 'amount'] = _data1.loc[time(11, 30): time(11, 31), 'amount'].sum() + _data1.loc[time(11, 30): time(11, 30), 'high'] = _data1.loc[time( + 11, 30): time(11, 31), 'high'].max() + _data1.loc[time(11, 30): time(11, 30), 'low'] = _data1.loc[time( + 11, 30): time(11, 31), 'low'].min() + _data1.loc[time(11, 30): time(11, 30), 'close'] = _data1.loc[time( + 11, 31): time(11, 31), 'close'].values + _data1.loc[time(11, 30): time(11, 30), 'vol'] = _data1.loc[time( + 11, 30): time(11, 31), 'vol'].sum() + _data1.loc[time(11, 30): time(11, 30), 'amount'] = _data1.loc[time( + 11, 30): time(11, 31), 'amount'].sum() _data1 = _data1.loc[time(9, 31): time(11, 30)] # afternoon min bar - _data2 = _data[time(13,0): time(15,0)].resample( - type_, closed='left', base=30, loffset=type_).apply({'price': 'ohlc', 'vol': 'sum', 'code': 'last', 'amount': 'sum'}) + _data2 = _data[time(13, 0): time(15, 0)].resample( + type_, closed='left', base=30, loffset=type_).apply({'price': 'ohlc', 'vol': 'sum', 'code': 'last', 'amount': 'sum'}) _data2.columns = _data2.columns.droplevel(0) # 沪市股票在 2018-08-20 起,尾盘 3 分钟集合竞价 if (pd.Timestamp(date) < pd.Timestamp('2018-08-20')) and (tick.code.iloc[0][0] == '6'): # 避免出现 tick 数据没有 1:00 的值 if len(_data.loc[time(13, 0): time(13, 0)]) > 0: - _data2.loc[time(15, 0): time(15, 0), 'high'] = _data2.loc[time(15, 0): time(15, 1), 'high'].max() - _data2.loc[time(15, 0): time(15, 0), 'low'] = _data2.loc[time(15, 0): time(15, 1), 'low'].min() - _data2.loc[time(15, 0): time(15, 0), 'close'] = _data2.loc[time(15, 1): time(15, 1), 'close'].values + _data2.loc[time(15, 0): time(15, 0), 'high'] = _data2.loc[time( + 15, 0): time(15, 1), 'high'].max() + _data2.loc[time(15, 0): time(15, 0), 'low'] = _data2.loc[time( + 15, 0): time(15, 1), 'low'].min() + _data2.loc[time(15, 0): time(15, 0), 'close'] = _data2.loc[time( + 15, 1): time(15, 1), 'close'].values else: # 避免出现 tick 数据没有 15:00 的值 if len(_data.loc[time(13, 0): time(13, 0)]) > 0: - _data2.loc[time(15, 0): time(15, 0)] = _data2.loc[time(15, 1): time(15, 1)].values + _data2.loc[time(15, 0): time(15, 0)] = _data2.loc[time( + 15, 1): time(15, 1)].values _data2 = _data2.loc[time(13, 1): time(15, 0)] resx = resx.append(_data1).append(_data2) resx['vol'] = resx['vol'] * 100.0 @@ -172,31 +186,6 @@ def QA_data_min_resample(min_data, type_='5min'): new_type {[type]} -- [description] """ - # ohlc_data=min_data.loc[:,['open','high','low','close']].stack().reset_index().rename(columns={0:'price'}).drop(['level_2'],axis=1).set_index('datetime',drop=False) - # vol=min_data.assign(vol1=0,vol2=0,vol3=0) - # L2=vol.loc[:,['volume','vol1','vol2','vol3']].stack().reset_index().rename(columns={0:'vol'}).drop(['level_2'],axis=1).set_index('datetime') - # tick=pd.concat([ohlc_data,L2.vol],axis=1) - # data = tick['price'].resample( - # type_, label='right', closed='left').ohlc() - - # data['volume'] = tick['vol'].resample( - # type_, label='right', closed='left').sum() - # data['code'] = tick.code.iloc[1] - # if 'date' not in tick.columns: - # tick=tick.assign(date=tick.datetime.apply(lambda x: str(x)[0:10])) - - # resx=pd.DataFrame() - # _temp = tick.drop_duplicates('date')['date'] - # for item in _temp: - # _data = data[item] - # _data = _data[time(9, 31):time(11, 30)].append( - # _data[time(13, 1):time(15, 0)]) - # resx = resx.append(_data) - # resx=resx.reset_index() - # data=resx.assign(date=resx['datetime'].apply(lambda x: str(x)[0:10])) - - # return data.fillna(method='ffill').set_index(['datetime', 'code'], drop=False).drop_duplicates() - try: min_data = min_data.reset_index().set_index('datetime', drop=False) except: @@ -208,15 +197,40 @@ def QA_data_min_resample(min_data, type_='5min'): for item in set(min_data.index.date): min_data_p = min_data.loc[str(item)] + n = min_data_p['{} 21:00:00'.format(item):].resample( + type_, base=30, closed='right', loffset=type_).apply(CONVERSION) + d = min_data_p[:'{} 11:30:00'.format(item)].resample( type_, base=30, closed='right', loffset=type_).apply(CONVERSION) f = min_data_p['{} 13:00:00'.format(item):].resample( type_, closed='right', loffset=type_).apply(CONVERSION) + resx = resx.append(d).append(f) return resx.dropna().reset_index().set_index(['datetime', 'code']) +def QA_data_futuremin_resample(min_data, type_='5min'): + """期货分钟线采样成大周期 + + + 分钟线采样成子级别的分钟线 + + future: + + vol ==> trade + amount X + """ + + min_data.tradeime = pd.to_datetime(min.tradetime) + + CONVERSION = {'code': 'first', 'open': 'first', 'high': 'max', 'low': 'min', + 'close': 'last', 'trade': 'sum', 'tradetime': 'last', 'date': 'last'} + resx = min_data.resample(type_, closed='right', + loffset=type_).apply(CONVERSION) + return resx.dropna().reset_index().set_index(['datetime', 'code']) + + def QA_data_day_resample(day_data, type_='w'): """日线降采样 diff --git a/QUANTAXIS/QAUtil/QADate_trade.py b/QUANTAXIS/QAUtil/QADate_trade.py index 6744cd55c..95468971d 100755 --- a/QUANTAXIS/QAUtil/QADate_trade.py +++ b/QUANTAXIS/QAUtil/QADate_trade.py @@ -473,7 +473,7 @@ def QA_util_future_to_tradedatetime(real_datetime): Returns: [type] -- [description] """ - if len(str(real_datetime))==19: + if len(str(real_datetime))>=19: dt = datetime.datetime.strptime(str(real_datetime)[0:19], '%Y-%m-%d %H:%M:%S') return dt if dt.time() Date: Mon, 7 Jan 2019 05:28:48 +0800 Subject: [PATCH 2/3] # --- QUANTAXIS/QAData/data_resample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QUANTAXIS/QAData/data_resample.py b/QUANTAXIS/QAData/data_resample.py index d33b278ea..74beeb0f4 100755 --- a/QUANTAXIS/QAData/data_resample.py +++ b/QUANTAXIS/QAData/data_resample.py @@ -222,7 +222,7 @@ def QA_data_futuremin_resample(min_data, type_='5min'): amount X """ - min_data.tradeime = pd.to_datetime(min.tradetime) + min_data.tradeime = pd.to_datetime(min_data.tradetime) CONVERSION = {'code': 'first', 'open': 'first', 'high': 'max', 'low': 'min', 'close': 'last', 'trade': 'sum', 'tradetime': 'last', 'date': 'last'} From f62349ab233c7eff9e308291ff35e0f7f199dfae Mon Sep 17 00:00:00 2001 From: yutiansut Date: Tue, 8 Jan 2019 07:45:59 +0800 Subject: [PATCH 3/3] # --- CHANGELOG.md | 17 +++++++++++++++++ QUANTAXIS/QAUtil/QALogs.py | 23 ++++++++++++++--------- QUANTAXIS/__init__.py | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2f55ec8d..4a1f180ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,23 @@ - [1.0.25](#1025) +## 1.2.6 + +1. 优化QADOCKER文档 +2. 增加QAORDER文档 +3. 优化了QALog模块在打印大量日志的时候无法知道其用途的问题 + +现在的quantaxis log 会以这个模式作为name: +``` + 'quantaxis_{}-{}-.log'.format(get_config(), os.sep, os.path.basename(sys.argv[0]).split('.py')[0], str(datetime.datetime.now().strftime( + '%Y-%m-%d-%H-%M-%S'))) +``` +4. 修改了QAUser的注册模块逻辑 +5. 增加了 QA_DataStruct_Min 和 QA_DataStruct_Day两个基类模型 +6. 修复settle的一个bug + + + ## 1.2.5 1. 对于QA.QA_util_code_tostr 增加 原先为list类型的支持 现在支持自动补全的 int/list/str 类型转 str diff --git a/QUANTAXIS/QAUtil/QALogs.py b/QUANTAXIS/QAUtil/QALogs.py index fda464474..df2b31a57 100755 --- a/QUANTAXIS/QAUtil/QALogs.py +++ b/QUANTAXIS/QAUtil/QALogs.py @@ -35,7 +35,7 @@ import configparser import datetime import os - +import sys from zenlog import logging from QUANTAXIS.QASetting.QALocalize import log_path, setting_path @@ -72,13 +72,18 @@ def get_config(): """2019-01-03 升级到warning级别 不然大量别的代码的log会批量输出出来 """ +try: + _name = '{}{}quantaxis_{}-{}-.log'.format(get_config(), os.sep, os.path.basename(sys.argv[0]).split('.py')[0], str(datetime.datetime.now().strftime( + '%Y-%m-%d-%H-%M-%S'))) +except: + _name = '{}{}quantaxis-{}-.log'.format(get_config(), os.sep, str(datetime.datetime.now().strftime( + '%Y-%m-%d-%H-%M-%S'))) logging.basicConfig(level=logging.WARNING, format='%(asctime)s QUANTAXIS>>> %(message)s', datefmt='%H:%M:%S', - filename='{}{}quantaxis-{}-.log'.format(get_config(), os.sep, str(datetime.datetime.now().strftime( - '%Y-%m-%d-%H-%M-%S'))), + filename=_name, filemode='w', ) console = logging.StreamHandler() @@ -91,7 +96,7 @@ def get_config(): #logging.info('start QUANTAXIS') -def QA_util_log_debug(logs, ui_log = None, ui_progress = None): +def QA_util_log_debug(logs, ui_log=None, ui_progress=None): """ QUANTAXIS Log Module @yutiansut @@ -101,7 +106,7 @@ def QA_util_log_debug(logs, ui_log = None, ui_progress = None): logging.debug(logs) -def QA_util_log_info(logs, ui_log = None, ui_progress = None, ui_progress_int_value = None): +def QA_util_log_info(logs, ui_log=None, ui_progress=None, ui_progress_int_value=None,): """ QUANTAXIS Log Module @yutiansut @@ -110,11 +115,11 @@ def QA_util_log_info(logs, ui_log = None, ui_progress = None, ui_progress_int_va """ logging.warning(logs) - #给GUI使用,更新当前任务到日志和进度 + # 给GUI使用,更新当前任务到日志和进度 if ui_log is not None: - if isinstance(logs, str) : + if isinstance(logs, str): ui_log.emit(logs) - if isinstance(logs, list) : + if isinstance(logs, list): for iStr in logs: ui_log.emit(iStr) @@ -122,7 +127,7 @@ def QA_util_log_info(logs, ui_log = None, ui_progress = None, ui_progress_int_va ui_progress.emit(ui_progress_int_value) -def QA_util_log_expection(logs, ui_log = None, ui_progress = None): +def QA_util_log_expection(logs, ui_log=None, ui_progress=None): """ QUANTAXIS Log Module @yutiansut diff --git a/QUANTAXIS/__init__.py b/QUANTAXIS/__init__.py index 8df1175b5..86bc6219d 100755 --- a/QUANTAXIS/__init__.py +++ b/QUANTAXIS/__init__.py @@ -32,7 +32,7 @@ 2017/4/8 """ -__version__ = '1.2.6.dev1' +__version__ = '1.2.6' __author__ = 'yutiansut' logo = ' \n \ ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n \