Skip to content

Commit

Permalink
Merge pull request #841 from yutiansut/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
yutiansut authored Oct 9, 2018
2 parents 78a681e + 8d0a184 commit 4b5360d
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 280 deletions.
66 changes: 39 additions & 27 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
---
name: Bug report
about: Create a report to help us improve
# 问题反馈

---
当您安装/使用QUANTAXIS的时候如果遇到任何问题, 您可以在这里提出,我们会在24小时内给您答复

**Describe the bug**
A clear and concise description of what the bug is.
## 您使用的QUANTAXIS版本号是什么?

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
```
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
```
## 您的系统信息(包括系统版本,系统架构(32/64),内存大小等等)
```
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
```

## 您的系统环境是什么?
```
- monodb
- nodejs(V9以下版本)
- python3.5/3.6
- docker(有无)
```
## 您需要反馈的问题
```
```
## 感谢您的反馈 如有意见和建议,请在此说明:
```
```
## 您的联系方式(QQ/EMAIL)
```
```


THANKS
by yutiansut
2017.12
7 changes: 0 additions & 7 deletions .github/ISSUE_TEMPLATE/custom.md

This file was deleted.

17 changes: 0 additions & 17 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

47 changes: 0 additions & 47 deletions .github/ISSUE_TEMPLATE/quantaxis_issue.md

This file was deleted.

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
File renamed without changes.
File renamed without changes.
103 changes: 103 additions & 0 deletions QUANTAXIS/QAApplication/OldBacktest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# @Hakase
import QUANTAXIS as QA
import numpy as np
import pandas as pd
import datetime
import sys
import random

class backtest():
"""依据回测场景的建模
"""

def __init__(self, start_time='2015-01-01', end_time='2018-09-24', init_cash=500000, code='RBL8', frequence=QA.FREQUENCE.FIFTEEN_MIN):
self.start_time = start_time
self.end_time = end_time
self.frequence = frequence
self.code = code
self.init_cach = init_cash
self.time_ = None
self.market_data_ = None
self.res= False

@property
def position(self):
return self.account.sell_available.get(self.code, 0)

@property
def time(self):
return self.time_

@property
def market_data(self):
return self.market_data_
# 自定义函数-------------------------------------------------------------------

@property
def hold_judge(self):
"""仓位判断器
Returns:
[type] -- [description]
"""

if self.account.cash/self.account.init_cash < 0.3:
return False
else:
return True

def before_backtest(self):
raise NotImplementedError

def before(self, *args, **kwargs):
self.before_backtest()
self.data_min = QA.QA_fetch_future_min_adv(
self.code, self.start_time, self.end_time, frequence=self.frequence)

self.data_day = QA.QA_fetch_future_day_adv(
self.code, self.start_time, self.end_time)

self.Broker = QA.QA_BacktestBroker()

def model(self, *arg, **kwargs):
raise NotImplementedError

def load_strategy(self, *arg, **kwargs):
# self.load_model(func1)
raise NotImplementedError

def run(self, *arg, **kwargs):
raise NotImplementedError

def buy(self, pos, towards):

self.account.receive_simpledeal(code=self.code,
trade_price=self.market_data.open, trade_amount=pos,
trade_towards=towards, trade_time=self.time,
message=towards)

def sell(self, pos, towards):
self.account.receive_simpledeal(code=self.code,
trade_price=self.market_data.open, trade_amount=pos,
trade_towards=towards, trade_time=self.time,
message=towards)

def main(self, *arg, **kwargs):
print(vars(self))
self.identity_code = '_'.join([str(x) for x in list(kwargs.values())])

self.backtest_cookie = 'future_{}_{}'.format(
datetime.datetime.now().time().__str__()[:8], self.identity_code)
self.account = QA.QA_Account(allow_sellopen=True, allow_t0=True, account_cookie=self.backtest_cookie,
market_type=QA.MARKET_TYPE.FUTURE_CN, frequence=self.frequence, init_cash=self.init_cash)

self.gen = self.data_min.reindex(
self.res) if self.res else self.data_min

for ind, item in self.gen.iterrows:
self.time_ = ind[0]
self.code = ind[1]

self.market_data_ = item
self.run()
7 changes: 0 additions & 7 deletions QUANTAXIS/QAApplication/QATradeRealtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,11 @@ def run(self):
_date = None

while QA_util_if_tradetime(self.now):






for data in self.ingest_data: # 对于在ingest_data中的数据
# <class 'QUANTAXIS.QAData.QADataStruct.QA_DataStruct_Stock_day'>
date = data.date[0]
if self.market_type is MARKET_TYPE.STOCK_CN: # 如果是股票市场
if _date != date: # 如果新的date

# 前一天的交易日已经过去
# 往 broker 和 account 发送 settle 事件
try:
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)
15 changes: 13 additions & 2 deletions QUANTAXIS/QAData/base_datastruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ def avg(self):
except:
return None

@property
@lru_cache()
def ndarray(self):
return self.to_numpy()

'''
########################################################################################################
计算统计相关的
Expand Down Expand Up @@ -591,6 +596,12 @@ def get_dict(self, time, code):
except Exception as e:
raise e

def reset_index(self):
return self.data.reset_index()

def rolling(self, N):
return self.groupby('code').rolling(N)

def plot(self, code=None):

def kline_formater(param):
Expand Down Expand Up @@ -829,7 +840,7 @@ def to_numpy(self):
"""
转换DataStruct为numpy.ndarray
"""
return np.asarray(self.data)
return np.asarray(self.data.reset_index())

def to_json(self):
"""
Expand Down Expand Up @@ -874,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
7 changes: 6 additions & 1 deletion QUANTAXIS/QAEngine/QABaseEventLoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@

class QABaseEventLoop(asyncio.AbstractEventLoop):
def __init__(self):
pass
pass

@property
def qa_loop(self):
try:
self.get_task_factory
Loading

0 comments on commit 4b5360d

Please sign in to comment.