Skip to content

Commit

Permalink
update fq/ update to 1.0.67
Browse files Browse the repository at this point in the history
update fq/ update to 1.0.67
  • Loading branch information
yutiansut authored Jul 16, 2018
2 parents 2cfe1ac + 3404c50 commit 01ab4fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<!-- TOC -->

- [QUANTAXIS 更新纪要](#quantaxis-更新纪要)
- [1.0.66 (unreleased)](#1066-unreleased)
- [1.0.67 (unreleased)](#1067-unreleased)
- [1.0.66](#1066)
- [1.0.65](#1065)
- [1.0.64](#1064)
- [1.0.63](#1063)
Expand Down Expand Up @@ -47,7 +48,9 @@
- [1.0.25](#1025)

<!-- /TOC -->
## 1.0.66 (unreleased)
## 1.0.67 (unreleased)

## 1.0.66

1. 修改series_struct 适配单个index的情景
2. 增加马科维茨有效前沿的研究/ 增加盘中涨停分析的研究 (research/)
Expand All @@ -62,6 +65,7 @@ QA.concat([QA.QA_DataStruct_Stock_min(QA.QA_DataStruct_Stock_realtime(QA.QA_fetc
5. @逝去的亮光 增加了LINUX环境下的CTP撤单接口
6. 增加了日线数据的降采样 QA.QA_data_day_resample(data,'w')

released in : JULY 17, 2018

## 1.0.65

Expand Down
43 changes: 23 additions & 20 deletions QUANTAXIS/QAData/data_fq.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,41 @@
import pandas as pd

from QUANTAXIS.QAFetch import QA_fetch_get_stock_day, QA_fetch_get_stock_xdxr
from QUANTAXIS.QAUtil import QA_util_log_info, DATABASE
from QUANTAXIS.QAUtil import DATABASE, QA_util_log_info


def QA_data_get_qfq(code, start, end):
'使用网络数据进行复权/需要联网'
xdxr_data = QA_fetch_get_stock_xdxr('tdx', code)
bfq_data = QA_fetch_get_stock_day(
'tdx', code, '1990-01-01', str(datetime.date.today())).dropna(axis=0)
return QA_data_make_qfq(bfq_data[start:end], xdxr_data)
return QA_data_make_qfq(bfq_data.loc[start:end], xdxr_data)


def QA_data_get_hfq(code, start, end):
'使用网络数据进行复权/需要联网'
xdxr_data = QA_fetch_get_stock_xdxr('tdx', code)
bfq_data = QA_fetch_get_stock_day(
'tdx', code, '1990-01-01', str(datetime.date.today())).dropna(axis=0)
return QA_data_make_hfq(bfq_data[start:end], xdxr_data)
return QA_data_make_hfq(bfq_data.loc[start:end], xdxr_data)


def QA_data_make_qfq(bfq_data, xdxr_data):
'使用数据库数据进行复权'
info = xdxr_data[xdxr_data['category'] == 1]
info = xdxr_data.query('category==1')
bfq_data = bfq_data.assign(if_trade=1)

if len(info) > 0:

data = pd.concat([bfq_data, info[['category']]
[bfq_data.index[0]:bfq_data.index[-1]]], axis=1)
data = pd.concat([bfq_data, info.loc[bfq_data.index[0]
:bfq_data.index[-1], ['category']]], axis=1)
data['if_trade'].fillna(value=0, inplace=True)
data = data.fillna(method='ffill')
data = pd.concat([data, info[['fenhong', 'peigu', 'peigujia',
'songzhuangu']][bfq_data.index[0]:bfq_data.index[-1]]], axis=1)
data = pd.concat([data, info.loc[bfq_data.index[0]:bfq_data.index[-1], ['fenhong', 'peigu', 'peigujia',
'songzhuangu']]], axis=1)
else:
data = pd.concat([bfq_data, info[['category', 'fenhong', 'peigu', 'peigujia',
'songzhuangu']]], axis=1)
data = pd.concat([bfq_data, info.loc[:, ['category', 'fenhong', 'peigu', 'peigujia',
'songzhuangu']]], axis=1)
data = data.fillna(0)
data['preclose'] = (data['close'].shift(1) * 10 - data['fenhong'] + data['peigu']
* data['peigujia']) / (10 + data['peigu'] + data['songzhuangu'])
Expand All @@ -87,21 +87,21 @@ def QA_data_make_qfq(bfq_data, xdxr_data):

def QA_data_make_hfq(bfq_data, xdxr_data):
'使用数据库数据进行复权'
info = xdxr_data[xdxr_data['category'] == 1]
info = xdxr_data.query('category==1')
bfq_data = bfq_data.assign(if_trade=1)

if len(info) > 0:
data = pd.concat([bfq_data, info[['category']]
[bfq_data.index[0]:bfq_data.index[-1]]], axis=1)
data = pd.concat([bfq_data, info.loc[bfq_data.index[0]
:bfq_data.index[-1], ['category']]], axis=1)

data['if_trade'].fillna(value=0, inplace=True)
data = data.fillna(method='ffill')

data = pd.concat([data, info[['fenhong', 'peigu', 'peigujia',
'songzhuangu']][bfq_data.index[0]:bfq_data.index[-1]]], axis=1)
data = pd.concat([data, info.loc[bfq_data.index[0]:bfq_data.index[-1], ['fenhong', 'peigu', 'peigujia',
'songzhuangu']]], axis=1)
else:
data = pd.concat([bfq_data, info[['category', 'fenhong', 'peigu', 'peigujia',
'songzhuangu']]], axis=1)
data = pd.concat([bfq_data, info.loc[:, ['category', 'fenhong', 'peigu', 'peigujia',
'songzhuangu']]], axis=1)
data = data.fillna(0)
data['preclose'] = (data['close'].shift(1) * 10 - data['fenhong'] + data['peigu']
* data['peigujia']) / (10 + data['peigu'] + data['songzhuangu'])
Expand Down Expand Up @@ -136,10 +136,13 @@ def __QA_fetch_stock_xdxr(code, format_='pd', collections=DATABASE.stock_xdxr):
'fenshu', 'liquidity_after', 'liquidity_before', 'name', 'peigu', 'peigujia',
'shares_after', 'shares_before', 'songzhuangu', 'suogu', 'xingquanjia'])
'股票 日线/分钟线 动态复权接口'

code = __data.index.levels[1][0] if isinstance(
__data.index, pd.core.indexes.multi.MultiIndex) else __data['code'][0]
if type_ in ['01', 'qfq']:
return QA_data_make_qfq(__data, __QA_fetch_stock_xdxr(__data['code'][0]))
return QA_data_make_qfq(__data, __QA_fetch_stock_xdxr(code))
elif type_ in ['02', 'hfq']:
return QA_data_make_hfq(__data, __QA_fetch_stock_xdxr(__data['code'][0]))
return QA_data_make_hfq(__data, __QA_fetch_stock_xdxr(code))
else:
QA_util_log_info('wrong fq type! Using qfq')
return QA_data_make_qfq(__data, __QA_fetch_stock_xdxr(__data['code'][0]))
return QA_data_make_qfq(__data, __QA_fetch_stock_xdxr(code))
2 changes: 1 addition & 1 deletion QUANTAXIS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
2017/4/8
"""

__version__ = '1.0.66'
__version__ = '1.0.67'
__author__ = 'yutiansut'
logo = ' \n \
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n \
Expand Down

0 comments on commit 01ab4fa

Please sign in to comment.