From 8bb3aa6b03be46c6b6880ad9707aea50fa540410 Mon Sep 17 00:00:00 2001 From: yutiansut Date: Tue, 28 Aug 2018 16:05:23 +0800 Subject: [PATCH] #update --- .../QAAnalysis.py | 0 .../QABacktest.py | 0 .../{QABacktest => QAApplication}/QAResult.py | 0 .../QAT0Backtest.py | 2 +- .../QATradeRealtime.py | 0 .../{QABacktest => QAApplication}/__init__.py | 0 .../backtest_setting.py | 0 QUANTAXIS/QACmd/__init__.py | 2 +- QUANTAXIS/QAFetch/QATushare.py | 53 +++++++++++++++---- QUANTAXIS/__init__.py | 6 +-- .../QABacktest_Bollinger_Bands.py | 2 +- .../QABacktest_Test/QABacktest_Test.py | 2 +- setup.py | 4 +- source/QUANTAXIS.QABacktest.rst | 20 +++---- source/QUANTAXIS.rst | 2 +- test_backtest/T0backtest.ipynb | 2 +- test_backtest/T0backtest.py | 2 +- test_backtest/backtest.py | 2 +- test_backtest/backtest_debug.py | 2 +- 19 files changed, 68 insertions(+), 33 deletions(-) rename QUANTAXIS/{QABacktest => QAApplication}/QAAnalysis.py (100%) mode change 100755 => 100644 rename QUANTAXIS/{QABacktest => QAApplication}/QABacktest.py (100%) mode change 100755 => 100644 rename QUANTAXIS/{QABacktest => QAApplication}/QAResult.py (100%) mode change 100755 => 100644 rename QUANTAXIS/{QABacktest => QAApplication}/QAT0Backtest.py (96%) rename QUANTAXIS/{QATrade => QAApplication}/QATradeRealtime.py (100%) rename QUANTAXIS/{QABacktest => QAApplication}/__init__.py (100%) mode change 100755 => 100644 rename QUANTAXIS/{QABacktest => QAApplication}/backtest_setting.py (100%) mode change 100755 => 100644 diff --git a/QUANTAXIS/QABacktest/QAAnalysis.py b/QUANTAXIS/QAApplication/QAAnalysis.py old mode 100755 new mode 100644 similarity index 100% rename from QUANTAXIS/QABacktest/QAAnalysis.py rename to QUANTAXIS/QAApplication/QAAnalysis.py diff --git a/QUANTAXIS/QABacktest/QABacktest.py b/QUANTAXIS/QAApplication/QABacktest.py old mode 100755 new mode 100644 similarity index 100% rename from QUANTAXIS/QABacktest/QABacktest.py rename to QUANTAXIS/QAApplication/QABacktest.py diff --git a/QUANTAXIS/QABacktest/QAResult.py b/QUANTAXIS/QAApplication/QAResult.py old mode 100755 new mode 100644 similarity index 100% rename from QUANTAXIS/QABacktest/QAResult.py rename to QUANTAXIS/QAApplication/QAResult.py diff --git a/QUANTAXIS/QABacktest/QAT0Backtest.py b/QUANTAXIS/QAApplication/QAT0Backtest.py similarity index 96% rename from QUANTAXIS/QABacktest/QAT0Backtest.py rename to QUANTAXIS/QAApplication/QAT0Backtest.py index bfaa1e9dd..696d544b0 100644 --- a/QUANTAXIS/QABacktest/QAT0Backtest.py +++ b/QUANTAXIS/QAApplication/QAT0Backtest.py @@ -1,6 +1,6 @@ # coding:utf-8 -from QUANTAXIS.QABacktest.QABacktest import QA_Backtest +from QUANTAXIS.QAApplication.QABacktest import QA_Backtest """ 日内t0的回测框架 diff --git a/QUANTAXIS/QATrade/QATradeRealtime.py b/QUANTAXIS/QAApplication/QATradeRealtime.py similarity index 100% rename from QUANTAXIS/QATrade/QATradeRealtime.py rename to QUANTAXIS/QAApplication/QATradeRealtime.py diff --git a/QUANTAXIS/QABacktest/__init__.py b/QUANTAXIS/QAApplication/__init__.py old mode 100755 new mode 100644 similarity index 100% rename from QUANTAXIS/QABacktest/__init__.py rename to QUANTAXIS/QAApplication/__init__.py diff --git a/QUANTAXIS/QABacktest/backtest_setting.py b/QUANTAXIS/QAApplication/backtest_setting.py old mode 100755 new mode 100644 similarity index 100% rename from QUANTAXIS/QABacktest/backtest_setting.py rename to QUANTAXIS/QAApplication/backtest_setting.py diff --git a/QUANTAXIS/QACmd/__init__.py b/QUANTAXIS/QACmd/__init__.py index 0141f8db1..85e237429 100755 --- a/QUANTAXIS/QACmd/__init__.py +++ b/QUANTAXIS/QACmd/__init__.py @@ -32,7 +32,7 @@ import subprocess import requests -from QUANTAXIS.QABacktest.QAAnalysis import QA_backtest_analysis_backtest +from QUANTAXIS.QAApplication.QAAnalysis import QA_backtest_analysis_backtest from QUANTAXIS.QAUtil import QA_util_log_info, QA_Setting, QA_util_mongo_initial from QUANTAXIS.QASU.main import (QA_SU_save_stock_list, QA_SU_save_stock_min, QA_SU_save_stock_xdxr, QA_SU_save_stock_block, QA_SU_save_stock_info,QA_SU_save_stock_info_tushare, diff --git a/QUANTAXIS/QAFetch/QATushare.py b/QUANTAXIS/QAFetch/QATushare.py index fd544b3b8..19a096aab 100755 --- a/QUANTAXIS/QAFetch/QATushare.py +++ b/QUANTAXIS/QAFetch/QATushare.py @@ -27,17 +27,52 @@ import pandas as pd import tushare as ts -from QUANTAXIS.QAUtil import (QA_util_date_int2str, QA_util_date_stamp, +from QUANTAXIS.QAUtil import (QA_util_date_int2str, QA_util_date_stamp, QASETTING, QA_util_log_info, QA_util_to_json_from_pandas) -# try: -# pro = ts.pro_api() -# except Exception as e: -# if isinstance(e, NameError): -# print('请设置tushare pro的token凭证码') -# else: -# print('请升级tushare 至最新版本 pip install tushare -U') -# print(e) + +def set_token(token=None): + try: + if token is None: + token = QASETTING.get_config('TSPRO', 'token', None) + else: + QASETTING.set_config('TSPRO', 'token', token) + ts.set_token(token) + except: + print('请升级tushare 至最新版本 pip install tushare -U') + + +def get_pro(): + try: + set_token() + pro = ts.pro_api() + except Exception as e: + if isinstance(e, NameError): + print('请设置tushare pro的token凭证码') + else: + print('请升级tushare 至最新版本 pip install tushare -U') + print(e) + pro = None + return pro + + +def QA_fetch_get_stock_adj(code, end=''): + """获取股票的复权因子 + + Arguments: + code {[type]} -- [description] + + Keyword Arguments: + end {str} -- [description] (default: {''}) + + Returns: + [type] -- [description] + """ + + + pro = get_pro() + adj = pro.adj_factor(ts_code=code, trade_date=end) + return adj def QA_fetch_get_stock_day(name, start='', end='', if_fq='01', type_='pd'): diff --git a/QUANTAXIS/__init__.py b/QUANTAXIS/__init__.py index 70ec2395c..e595e509e 100755 --- a/QUANTAXIS/__init__.py +++ b/QUANTAXIS/__init__.py @@ -106,10 +106,10 @@ from QUANTAXIS.QAARP.QAUser import QA_User from QUANTAXIS.QAARP.QAStrategy import QA_Strategy # Backtest -from QUANTAXIS.QABacktest.QABacktest import QA_Backtest +from QUANTAXIS.QAApplication.QABacktest import QA_Backtest -from QUANTAXIS.QABacktest.QAAnalysis import QA_backtest_analysis_backtest -from QUANTAXIS.QABacktest.QAResult import backtest_result_analyzer +from QUANTAXIS.QAApplication.QAAnalysis import QA_backtest_analysis_backtest +from QUANTAXIS.QAApplication.QAResult import backtest_result_analyzer # ENGINE from QUANTAXIS.QAEngine import QA_Thread, QA_Event, QA_Worker, QA_Task, QA_Engine diff --git a/QUANTAXIS_Test/QABacktest_Test/QABacktest_Bollinger_Bands.py b/QUANTAXIS_Test/QABacktest_Test/QABacktest_Bollinger_Bands.py index 7e0628202..53be4d0f9 100644 --- a/QUANTAXIS_Test/QABacktest_Test/QABacktest_Bollinger_Bands.py +++ b/QUANTAXIS_Test/QABacktest_Test/QABacktest_Bollinger_Bands.py @@ -8,7 +8,7 @@ from QUANTAXIS.QAARP.QARisk import QA_Performance, QA_Risk from QUANTAXIS.QAARP.QAStrategy import QA_Strategy from QUANTAXIS.QAARP.QAUser import QA_User -from QUANTAXIS.QABacktest.QABacktest import QA_Backtest +from QUANTAXIS.QAApplication.QABacktest import QA_Backtest from QUANTAXIS.QAFetch import QAQuery_Advance from QUANTAXIS.QAIndicator import QA_indicator_BOLL from QUANTAXIS.QAUtil.QADate_trade import (QA_util_get_last_day, diff --git a/QUANTAXIS_Test/QABacktest_Test/QABacktest_Test.py b/QUANTAXIS_Test/QABacktest_Test/QABacktest_Test.py index 6c8a456f9..b8be0674d 100644 --- a/QUANTAXIS_Test/QABacktest_Test/QABacktest_Test.py +++ b/QUANTAXIS_Test/QABacktest_Test/QABacktest_Test.py @@ -7,7 +7,7 @@ from QUANTAXIS.QAARP.QARisk import QA_Performance, QA_Risk from QUANTAXIS.QAARP.QAStrategy import QA_Strategy from QUANTAXIS.QAARP.QAUser import QA_User -from QUANTAXIS.QABacktest.QABacktest import QA_Backtest +from QUANTAXIS.QAApplication.QABacktest import QA_Backtest from QUANTAXIS.QAFetch.QAQuery import QA_fetch_stock_day from QUANTAXIS.QAIndicator import QA_indicator_MA from QUANTAXIS.QAUtil.QADate import QA_util_datetime_to_strdate diff --git a/setup.py b/setup.py index 59a0344ac..35d650ec1 100644 --- a/setup.py +++ b/setup.py @@ -66,8 +66,8 @@ def read(fname): """ 名字,一般放你包的名字即可 """ -PACKAGES = ["QUANTAXIS", "QUANTAXIS.QAFetch", "QUANTAXIS.QACmd", "QUANTAXIS.QAMarket", 'QUANTAXIS.QAWeb', 'QUANTAXIS.QATrade', 'QUANTAXIS.QASetting', - "QUANTAXIS.QABacktest", "QUANTAXIS.QAEngine", "QUANTAXIS.QAData", 'QUANTAXIS.QAData.proto', "QUANTAXIS.QAAnalysis", 'QUANTAXIS.QASelector', +PACKAGES = ["QUANTAXIS", "QUANTAXIS.QAFetch", "QUANTAXIS.QACmd", "QUANTAXIS.QAMarket", 'QUANTAXIS.QAWeb', 'QUANTAXIS.QASetting', + "QUANTAXIS.QAApplication", "QUANTAXIS.QAEngine", "QUANTAXIS.QAData", 'QUANTAXIS.QAData.proto', "QUANTAXIS.QAAnalysis", 'QUANTAXIS.QASelector', "QUANTAXIS.QASU", "QUANTAXIS.QAUtil", "QUANTAXIS.QAARP", "QUANTAXIS.QAIndicator", "QUANTAXIS_CRAWLY", "QUANTAXIS.QAView"] """ 包含的包,可以多个,这是一个列表 diff --git a/source/QUANTAXIS.QABacktest.rst b/source/QUANTAXIS.QABacktest.rst index adcc84e69..08a13ab70 100644 --- a/source/QUANTAXIS.QABacktest.rst +++ b/source/QUANTAXIS.QABacktest.rst @@ -1,37 +1,37 @@ -QUANTAXIS.QABacktest package +QUANTAXIS.QAApplication package ============================ Submodules ---------- -QUANTAXIS.QABacktest.QAAnalysis module +QUANTAXIS.QAApplication.QAAnalysis module -------------------------------------- -.. automodule:: QUANTAXIS.QABacktest.QAAnalysis +.. automodule:: QUANTAXIS.QAApplication.QAAnalysis :members: :undoc-members: :show-inheritance: -QUANTAXIS.QABacktest.QABacktest module +QUANTAXIS.QAApplication.QABacktest module -------------------------------------- -.. automodule:: QUANTAXIS.QABacktest.QABacktest +.. automodule:: QUANTAXIS.QAApplication.QABacktest :members: :undoc-members: :show-inheritance: -QUANTAXIS.QABacktest.QAResult module +QUANTAXIS.QAApplication.QAResult module ------------------------------------ -.. automodule:: QUANTAXIS.QABacktest.QAResult +.. automodule:: QUANTAXIS.QAApplication.QAResult :members: :undoc-members: :show-inheritance: -QUANTAXIS.QABacktest.backtest\_setting module +QUANTAXIS.QAApplication.backtest\_setting module --------------------------------------------- -.. automodule:: QUANTAXIS.QABacktest.backtest_setting +.. automodule:: QUANTAXIS.QAApplication.backtest_setting :members: :undoc-members: :show-inheritance: @@ -40,7 +40,7 @@ QUANTAXIS.QABacktest.backtest\_setting module Module contents --------------- -.. automodule:: QUANTAXIS.QABacktest +.. automodule:: QUANTAXIS.QAApplication :members: :undoc-members: :show-inheritance: diff --git a/source/QUANTAXIS.rst b/source/QUANTAXIS.rst index e5a40b09e..b26f6e08f 100644 --- a/source/QUANTAXIS.rst +++ b/source/QUANTAXIS.rst @@ -8,7 +8,7 @@ Subpackages QUANTAXIS.QAARP QUANTAXIS.QAAnalysis - QUANTAXIS.QABacktest + QUANTAXIS.QAApplication QUANTAXIS.QACmd QUANTAXIS.QAData QUANTAXIS.QAEngine diff --git a/test_backtest/T0backtest.ipynb b/test_backtest/T0backtest.ipynb index 33e598682..1f4f1dd2b 100644 --- a/test_backtest/T0backtest.ipynb +++ b/test_backtest/T0backtest.ipynb @@ -333,7 +333,7 @@ "\n", "from QUANTAXIS.QAARP.QARisk import QA_Risk\n", "from QUANTAXIS.QAARP.QAUser import QA_User\n", - "from QUANTAXIS.QABacktest.QABacktest import QA_Backtest\n", + "from QUANTAXIS.QAApplication.QABacktest import QA_Backtest\n", "from QUANTAXIS.QAUtil.QALogs import QA_util_log_info\n", "from QUANTAXIS.QAUtil.QAParameter import FREQUENCE, MARKET_TYPE\n", "\n", diff --git a/test_backtest/T0backtest.py b/test_backtest/T0backtest.py index 631e0a311..71929f534 100644 --- a/test_backtest/T0backtest.py +++ b/test_backtest/T0backtest.py @@ -57,7 +57,7 @@ def on_bar(self, event): from QUANTAXIS.QAARP.QARisk import QA_Risk from QUANTAXIS.QAARP.QAUser import QA_User -from QUANTAXIS.QABacktest.QABacktest import QA_Backtest +from QUANTAXIS.QAApplication.QABacktest import QA_Backtest from QUANTAXIS.QAUtil.QALogs import QA_util_log_info from QUANTAXIS.QAUtil.QAParameter import FREQUENCE, MARKET_TYPE diff --git a/test_backtest/backtest.py b/test_backtest/backtest.py index a49353a79..20527fa42 100755 --- a/test_backtest/backtest.py +++ b/test_backtest/backtest.py @@ -25,7 +25,7 @@ from QUANTAXIS.QAARP.QARisk import QA_Risk from QUANTAXIS.QAARP.QAUser import QA_User -from QUANTAXIS.QABacktest.QABacktest import QA_Backtest +from QUANTAXIS.QAApplication.QABacktest import QA_Backtest from QUANTAXIS.QAUtil.QALogs import QA_util_log_info from QUANTAXIS.QAUtil.QAParameter import FREQUENCE, MARKET_TYPE from test_backtest.minstrategy import MAMINStrategy diff --git a/test_backtest/backtest_debug.py b/test_backtest/backtest_debug.py index 30d6038ba..cebd622c8 100644 --- a/test_backtest/backtest_debug.py +++ b/test_backtest/backtest_debug.py @@ -25,7 +25,7 @@ from QUANTAXIS.QAARP.QARisk import QA_Risk from QUANTAXIS.QAARP.QAUser import QA_User -from QUANTAXIS.QABacktest.QABacktest import QA_Backtest +from QUANTAXIS.QAApplication.QABacktest import QA_Backtest from QUANTAXIS.QAUtil.QALogs import QA_util_log_info from QUANTAXIS.QAUtil.QAParameter import FREQUENCE, MARKET_TYPE from test_backtest.minstrategy import MAMINStrategy