From 4645b3496cdec6c1ad1b11e3caa31c7c81956de6 Mon Sep 17 00:00:00 2001 From: yutiansut Date: Sun, 23 Feb 2020 12:10:21 +0800 Subject: [PATCH 1/5] # --- QUANTAXIS/QAData/base_datastruct.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QUANTAXIS/QAData/base_datastruct.py b/QUANTAXIS/QAData/base_datastruct.py index 2bc15830a..880147869 100755 --- a/QUANTAXIS/QAData/base_datastruct.py +++ b/QUANTAXIS/QAData/base_datastruct.py @@ -920,7 +920,7 @@ def agg(self, func, axis=0, *args, **kwargs): def aggregate(self, func, axis=0, *args, **kwargs): return self.new(self.data.aggregate(func, axis=0, *args, **kwargs)) - def tail(self, lens): + def tail(self, lens=5): """返回最后Lens个值的DataStruct Arguments: @@ -932,7 +932,7 @@ def tail(self, lens): return self.new(self.data.tail(lens)) - def head(self, lens): + def head(self, lens=5): """返回最前lens个值的DataStruct Arguments: From db6d04ad5821cb8809d9b3376b9db7f0ef67fbba Mon Sep 17 00:00:00 2001 From: Chiang Hao <864413714@qq.com> Date: Mon, 24 Feb 2020 18:21:19 +0800 Subject: [PATCH 2/5] Update QAAnalysis_block.py --- QUANTAXIS/QAAnalysis/QAAnalysis_block.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QUANTAXIS/QAAnalysis/QAAnalysis_block.py b/QUANTAXIS/QAAnalysis/QAAnalysis_block.py index 2c69e07b2..d41f4cea1 100755 --- a/QUANTAXIS/QAAnalysis/QAAnalysis_block.py +++ b/QUANTAXIS/QAAnalysis/QAAnalysis_block.py @@ -48,7 +48,7 @@ def market_data(self): @property @lru_cache() def market_value(self): - return self.market_data.add_func(QA_data_marketvalue) + return QA_data_marketvalue(self.market_data.data) @property def week_data(self): From e3dbac6f2f796104fd642868e8226f849718e98a Mon Sep 17 00:00:00 2001 From: Chiang Hao <864413714@qq.com> Date: Mon, 24 Feb 2020 18:23:36 +0800 Subject: [PATCH 3/5] Update data_marketvalue.py --- QUANTAXIS/QAData/data_marketvalue.py | 30 +++++++++++----------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/QUANTAXIS/QAData/data_marketvalue.py b/QUANTAXIS/QAData/data_marketvalue.py index 6e7457ee9..16a982488 100755 --- a/QUANTAXIS/QAData/data_marketvalue.py +++ b/QUANTAXIS/QAData/data_marketvalue.py @@ -35,32 +35,30 @@ def QA_data_calc_marketvalue(data, xdxr): ['shares_after', 'liquidity_after']].dropna() res = pd.concat([data, mv], axis=1) - res = res.assign( - shares=res.shares_after.fillna(method='ffill'), - lshares=res.liquidity_after.fillna(method='ffill') + shares=res.shares_after.groupby(level=1).fillna(method='ffill'), + lshares=res.liquidity_after.groupby(level=1).fillna(method='ffill') ) - return res.assign(mv=res.close*res.shares*10000, liquidity_mv=res.close*res.lshares*10000).drop(['shares_after', 'liquidity_after'], axis=1)\ - .loc[(slice(data.index.remove_unused_levels().levels[0][0],data.index.remove_unused_levels().levels[0][-1]),slice(None)),:] - + return res.assign(mv=res.close*res.shares*10000, liquidity_mv=res.close*res.lshares*10000)\ + .drop(['shares_after', 'liquidity_after'], axis=1)\ + .loc[(slice(data.index.remove_unused_levels().levels[0][0],data.index.remove_unused_levels().levels[0][-1]),slice(None)),:] def QA_data_marketvalue(data): def __QA_fetch_stock_xdxr( - code, + code_list, format_='pd', collections=DATABASE.stock_xdxr ): '获取股票除权信息/数据库' try: data = pd.DataFrame( - [item for item in collections.find({'code': code})] - ).drop(['_id'], - axis=1) + [item for item in collections.find({'code': {"$in": code_list} + },{"_id": 0})]) data['date'] = pd.to_datetime(data['date']) return data.drop_duplicates( - 'date', + ['date', 'code'], keep='last' ).set_index(['date', 'code'], @@ -86,10 +84,6 @@ def __QA_fetch_stock_xdxr( 'suogu', 'xingquanjia' ] - ) - - code = data.index.remove_unused_levels().levels[1][0] if isinstance( - data.index, - pd.core.indexes.multi.MultiIndex - ) else data['code'][0] - return QA_data_calc_marketvalue(data, __QA_fetch_stock_xdxr(code)) + ) + code_list = data.index.remove_unused_levels().levels[1].tolist() + return QA_data_calc_marketvalue_new(data, __QA_fetch_stock_xdxr(code_list)) From a933133a99ca4169ad98019c9f61274be6a5f2b5 Mon Sep 17 00:00:00 2001 From: Chiang Hao <864413714@qq.com> Date: Mon, 24 Feb 2020 18:32:48 +0800 Subject: [PATCH 4/5] Update data_marketvalue.py --- QUANTAXIS/QAData/data_marketvalue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QUANTAXIS/QAData/data_marketvalue.py b/QUANTAXIS/QAData/data_marketvalue.py index 16a982488..d8d7e69af 100755 --- a/QUANTAXIS/QAData/data_marketvalue.py +++ b/QUANTAXIS/QAData/data_marketvalue.py @@ -86,4 +86,4 @@ def __QA_fetch_stock_xdxr( ] ) code_list = data.index.remove_unused_levels().levels[1].tolist() - return QA_data_calc_marketvalue_new(data, __QA_fetch_stock_xdxr(code_list)) + return QA_data_calc_marketvalue(data, __QA_fetch_stock_xdxr(code_list)) From 34c4eb53b18c8b9b02fb1470eebdab7c2e59096c Mon Sep 17 00:00:00 2001 From: yutiansut Date: Tue, 25 Feb 2020 02:57:07 +0800 Subject: [PATCH 5/5] #update to 1.9.6 --- QUANTAXIS/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QUANTAXIS/__init__.py b/QUANTAXIS/__init__.py index fb5d195bf..c1af7c54c 100755 --- a/QUANTAXIS/__init__.py +++ b/QUANTAXIS/__init__.py @@ -31,7 +31,7 @@ 2017/4/8 """ -__version__ = '1.9.6' +__version__ = '1.9.7' __author__ = 'yutiansut' import argparse