Skip to content

Commit

Permalink
Merge pull request #1471 from yutiansut/master
Browse files Browse the repository at this point in the history
sync update to 1.9.6
  • Loading branch information
yutiansut authored Feb 24, 2020
2 parents 7d2e98b + 34c4eb5 commit c80868b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion QUANTAXIS/QAAnalysis/QAAnalysis_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions QUANTAXIS/QAData/base_datastruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
30 changes: 12 additions & 18 deletions QUANTAXIS/QAData/data_marketvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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(data, __QA_fetch_stock_xdxr(code_list))
2 changes: 1 addition & 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.9.6'
__version__ = '1.9.7'
__author__ = 'yutiansut'

import argparse
Expand Down

0 comments on commit c80868b

Please sign in to comment.