Skip to content

Commit

Permalink
update datastruct_func
Browse files Browse the repository at this point in the history
  • Loading branch information
yutiansut committed Oct 9, 2018
1 parent 4c9b615 commit 8d0a184
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
1. 增加了商品期权的分钟线获取
2. 优化了QA_Account的存储
3. 修复了QA_PortfolioView的bug
4. DataStruct 增加了 rolling(N)的方法


## 1.1.7

Expand Down
28 changes: 14 additions & 14 deletions QUANTAXIS/QAData/QAIndicatorStruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, data):
self.data = data

def __repr__(self):
return '< QA_DATASTRUCT_INDICATOR FROM {} TO {} WITH {} CODES >'.format(self.data.index.levels[0][0],self.data.index.levels[0][-1],len(self.data.index.levels[1]))
return '< QA_DATASTRUCT_INDICATOR FROM {} TO {} WITH {} CODES >'.format(self.data.index.levels[0][0], self.data.index.levels[0][-1], len(self.data.index.levels[1]))

@property
def index(self):
Expand All @@ -49,7 +49,7 @@ def get_indicator(self, time, code, indicator_name=None):
获取某一时间的某一只股票的指标
"""
try:
return self.data.loc[(pd.Timestamp(time), code),indicator_name]
return self.data.loc[(pd.Timestamp(time), code), indicator_name]
except:
raise ValueError('CANNOT FOUND THIS DATE&CODE')

Expand All @@ -71,9 +71,9 @@ def get_timerange(self, start, end, code=None):
except:
return ValueError('CANNOT FOUND THIS TIME RANGE')

def groupby(self,by=None, axis=0, level=None, as_index=True, sort=False, group_keys=True, squeeze=False, **kwargs):
def groupby(self, by=None, axis=0, level=None, as_index=True, sort=False, group_keys=True, squeeze=False, **kwargs):
"""仿dataframe的groupby写法,但控制了by的code和datetime
Keyword Arguments:
by {[type]} -- [description] (default: {None})
axis {int} -- [description] (default: {0})
Expand All @@ -83,18 +83,18 @@ def groupby(self,by=None, axis=0, level=None, as_index=True, sort=False, group_k
group_keys {bool} -- [description] (default: {True})
squeeze {bool} -- [description] (default: {False})
observed {bool} -- [description] (default: {False})
Returns:
[type] -- [description]
"""

if by==self.index.names[1]:
by=None
level=1
elif by== self.index.names[0]:
by =None
level=0
return self.data.groupby(by=by,axis=axis,level=level,as_index=as_index,sort=sort,group_keys=group_keys,squeeze=squeeze)
if by == self.index.names[1]:
by = None
level = 1
elif by == self.index.names[0]:
by = None
level = 0
return self.data.groupby(by=by, axis=axis, level=level, as_index=as_index, sort=sort, group_keys=group_keys, squeeze=squeeze)

def add_func(self,func,*args,**kwargs):
return self.groupby(level=1,as_index=False,group_keys=False).apply(func,*args,**kwargs)
def add_func(self, func, *args, **kwargs):
return self.groupby(level=1, as_index=False, group_keys=False).apply(func, raw=True, *args, **kwargs)
2 changes: 1 addition & 1 deletion QUANTAXIS/QAData/base_datastruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def splits(self):
# self.data.loc[(slice(None), x), :], *arg, **kwargs), self.code))).sort_index()

def add_func(self, func, *arg, **kwargs):
return self.groupby(level=1, sort=False).apply(func, *arg, **kwargs)
return self.groupby(level=1, sort=False).apply(func, raw=True, *arg, **kwargs)

def pivot(self, column_):
"""增加对于多列的支持"""
Expand Down
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.1.8.dev2'
__version__ = '1.1.8.dev3'
__author__ = 'yutiansut'
logo = ' \n \
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n \
Expand Down

0 comments on commit 8d0a184

Please sign in to comment.