diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b73537336..7495b5ead 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -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 diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md deleted file mode 100644 index 99bb9a009..000000000 --- a/.github/ISSUE_TEMPLATE/custom.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -name: Custom issue template -about: Describe this issue template's purpose here. - ---- - - diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 066b2d920..000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/quantaxis_issue.md b/.github/ISSUE_TEMPLATE/quantaxis_issue.md deleted file mode 100644 index 7495b5ead..000000000 --- a/.github/ISSUE_TEMPLATE/quantaxis_issue.md +++ /dev/null @@ -1,47 +0,0 @@ -# 问题反馈 - -当您安装/使用QUANTAXIS的时候如果遇到任何问题, 您可以在这里提出,我们会在24小时内给您答复 - -## 您使用的QUANTAXIS版本号是什么? - -``` - - - -``` -## 您的系统信息(包括系统版本,系统架构(32/64),内存大小等等) -``` - - - - - -``` - -## 您的系统环境是什么? -``` -- monodb -- nodejs(V9以下版本) -- python3.5/3.6 -- docker(有无) -``` -## 您需要反馈的问题 -``` - - -``` -## 感谢您的反馈 如有意见和建议,请在此说明: -``` - - - -``` -## 您的联系方式(QQ/EMAIL) -``` - -``` - - -THANKS -by yutiansut -2017.12 diff --git a/CHANGELOG.md b/CHANGELOG.md index 41efafd35..5cd779677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,8 @@ 1. 增加了商品期权的分钟线获取 2. 优化了QA_Account的存储 3. 修复了QA_PortfolioView的bug +4. DataStruct 增加了 rolling(N)的方法 + ## 1.1.7 diff --git a/shipane_install_memo.md b/Documents/shipane_install_memo.md similarity index 100% rename from shipane_install_memo.md rename to Documents/shipane_install_memo.md diff --git "a/\351\200\211\350\202\241\346\250\241\345\235\227.md" "b/Documents/\351\200\211\350\202\241\346\250\241\345\235\227.md" similarity index 100% rename from "\351\200\211\350\202\241\346\250\241\345\235\227.md" rename to "Documents/\351\200\211\350\202\241\346\250\241\345\235\227.md" diff --git a/QUANTAXIS/QAApplication/OldBacktest.py b/QUANTAXIS/QAApplication/OldBacktest.py new file mode 100644 index 000000000..f01dac857 --- /dev/null +++ b/QUANTAXIS/QAApplication/OldBacktest.py @@ -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() \ No newline at end of file diff --git a/QUANTAXIS/QAApplication/QATradeRealtime.py b/QUANTAXIS/QAApplication/QATradeRealtime.py index 74945ccc0..f8bb2a4d9 100644 --- a/QUANTAXIS/QAApplication/QATradeRealtime.py +++ b/QUANTAXIS/QAApplication/QATradeRealtime.py @@ -88,18 +88,11 @@ def run(self): _date = None while QA_util_if_tradetime(self.now): - - - - - - for data in self.ingest_data: # 对于在ingest_data中的数据 # date = data.date[0] if self.market_type is MARKET_TYPE.STOCK_CN: # 如果是股票市场 if _date != date: # 如果新的date - # 前一天的交易日已经过去 # 往 broker 和 account 发送 settle 事件 try: diff --git a/QUANTAXIS/QAData/QAIndicatorStruct.py b/QUANTAXIS/QAData/QAIndicatorStruct.py index c29a7cdd0..30882080e 100644 --- a/QUANTAXIS/QAData/QAIndicatorStruct.py +++ b/QUANTAXIS/QAData/QAIndicatorStruct.py @@ -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): @@ -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') @@ -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}) @@ -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) \ No newline at end of file + def add_func(self, func, *args, **kwargs): + return self.groupby(level=1, as_index=False, group_keys=False).apply(func, raw=True, *args, **kwargs) diff --git a/QUANTAXIS/QAData/base_datastruct.py b/QUANTAXIS/QAData/base_datastruct.py index f62ed1b39..89240172c 100644 --- a/QUANTAXIS/QAData/base_datastruct.py +++ b/QUANTAXIS/QAData/base_datastruct.py @@ -367,6 +367,11 @@ def avg(self): except: return None + @property + @lru_cache() + def ndarray(self): + return self.to_numpy() + ''' ######################################################################################################## 计算统计相关的 @@ -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): @@ -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): """ @@ -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_): """增加对于多列的支持""" diff --git a/QUANTAXIS/QAEngine/QABaseEventLoop.py b/QUANTAXIS/QAEngine/QABaseEventLoop.py index dad1369b6..e83772370 100644 --- a/QUANTAXIS/QAEngine/QABaseEventLoop.py +++ b/QUANTAXIS/QAEngine/QABaseEventLoop.py @@ -5,4 +5,9 @@ class QABaseEventLoop(asyncio.AbstractEventLoop): def __init__(self): - pass \ No newline at end of file + pass + + @property + def qa_loop(self): + try: + self.get_task_factory \ No newline at end of file diff --git a/QUANTAXIS/__init__.py b/QUANTAXIS/__init__.py index 172680de4..45a3669d1 100755 --- a/QUANTAXIS/__init__.py +++ b/QUANTAXIS/__init__.py @@ -32,7 +32,7 @@ 2017/4/8 """ -__version__ = '1.1.8.dev2' +__version__ = '1.1.8.dev3' __author__ = 'yutiansut' logo = ' \n \ ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n \ diff --git a/about_quantaxis.md b/about_quantaxis.md deleted file mode 100644 index 556673d1a..000000000 --- a/about_quantaxis.md +++ /dev/null @@ -1,31 +0,0 @@ - -QUANTAXIS - -## 数据结构 - -QUANTAXIS 的核心数据是DATASTRUCT,datastruct目前是基于pandas.DataFrame的一个结构. -QUANTAXIS支持5种类型的数据结构: - - -- list -- numpy ndarray -- json/dict -- pandas dataframe,series -- DATASTRUCT - -从速度和性能考虑, dict是取出速度最快的结构, 可以作为临时的缓存使用. numpy因为cython加速的原因,在运算的过程中速度最快, pandas的索引导致他的计算较慢,但比较人性化 - - -## 统一数据接口 - -```python -QA.QA_quoation(code, start, end, frequence, market, source, output) - code {str/list} -- 证券/股票的代码 - start {str} -- 开始日期 - end {str} -- 结束日期 - frequence {enum} -- 频率 QA.FREQUENCE - market {enum} -- 市场 QA.MARKET_TYPE - source {enum} -- 来源 QA.DATASOURCE - output {enum} -- 输出类型 QA.OUTPUT_FORMAT -``` - diff --git a/recent_job.md b/recent_job.md deleted file mode 100644 index d61ede917..000000000 --- a/recent_job.md +++ /dev/null @@ -1,22 +0,0 @@ -# 近期任务 - - - -- 选股模式 (最好是一行代码能实现选股 或者是组合选股) . - ``` - https://github.com/QUANTAXIS/QUANTAXIS/blob/master/%E9%80%89%E8%82%A1%E6%A8%A1%E5%9D%97.md - ``` - - - -- 版块--版块产业链--版块消息面-- 异动个股 - - ``` - https://github.com/QUANTAXIS/market_review - ``` - -- 基于react/electron的桌面级可视化客户端 - - ``` - https://github.com/QUANTAXIS/qadesk - ``` \ No newline at end of file diff --git a/whatcanqado.md b/whatcanqado.md deleted file mode 100644 index 5a6dd1d45..000000000 --- a/whatcanqado.md +++ /dev/null @@ -1,104 +0,0 @@ -# QUANTAXIS的功能 - - -### 1. 行情服务 - -#### 1.1 股票/期货/期权/美股/外汇/宏观的历史/实时行情(日线/分钟线/tick/实时五档)服务 - -参见 [QUANTAXIS的数据获取指南](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/DataFetch.md) - -#### 1.2 财务/基本面/宏观数据 - -参见 [QUANTAXIS财务指标](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/financial_means.md) - -#### 1.3 自定义数据源的数据 - -参见 [QUANTAXIS WEB 爬虫](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/crawler.md) - -### 2. 数据运维服务 - -一键更新 参见[WINDOWS数据自动更新](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/config/windows_autojob_updatedata.md) - - -### 3 分析服务 - -#### 3.1 专门为A股股票数据适配的数据结构 - -参见 [QUANTAXIS的数据结构](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/DataStruct.md) - -参见 [QUANTAXIS行情研究](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/analysis.md) - -#### 3.2 精心为A股指标计算适配的指标类 - -参见 [QUANTAXIS指标系统](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/indicators.md) - - -### 4. 可扩展事件驱动框架 - -参见 [QUANTAXIS事件框架](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/about_event.md) - - -### 5. 回测服务 - -#### 5.1 股票/日内t0/ 的日线/分钟线级别回测 - -参见 [QUANTAXIS的账户结构](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/account.md) - -参见 [QUANTAXIS 账户风险分析插件指南](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/risk.md) - -参见 [QUANTAXIS回测委托成交结算的说明](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/orderanddeal.md) - -参见 [QUANTAXIS回测分析](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/backtestanalysis.md) - -参见 [常见策略整理](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/strategy.md) - -参见 [简单策略回测详解](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/QUANTAXIS回测分析全过程讲解.md) - -参见 [T0交易的账户详解](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/TEST_ORDER_BACKTEST_T0.md) - -### 6 实盘 - -#### 6.1 股票(实盘易) - -实盘易插件 参见[实盘易](http://www.iguuu.com/e?x=18839) - -实盘易安装注意 参见[安装注意](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/shipane_install_memo.md) - -#### 6.2 期货(python3 CTP win/mac/linux) - -参见 [LINUX CTP](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/QUANTAXIS_Trade/LINUXCTP) - -参见 [WINDOWS CTP](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/QUANTAXIS_Trade/WindowsCTP) - -### 7 网站HTTP服务 - -#### 7.1 网站后台标准化接口 - -参见 [QUANTAXIS WEB API说明](https://github.com/QUANTAXIS/QUANTAXIS/blob/master/Documents/backendapi.md) - - - -预计实现: -- 选股模式 (最好是一行代码能实现选股 或者是组合选股) . - ``` - https://github.com/QUANTAXIS/QUANTAXIS/blob/master/blob/master/%E9%80%89%E8%82%A1%E6%A8%A1%E5%9D%97.md - ``` -- 财务函数的fetch优化(一个函数 全市场/多来源/多类型) - -- 日内实时的检测/实时采样重采样 - - ``` - https://github.com/QUANTAXIS/QUANTAXIS/blob/master/blob/master/QUANTAXIS_Runtime/readme.md - ``` - -- 版块--版块产业链--版块消息面-- 异动个股 - - ``` - https://github.com/QUANTAXIS/market_review - ``` - -- 基于react/electron的桌面级可视化客户端 - - ``` - https://github.com/QUANTAXIS/qadesk - ``` \ No newline at end of file