From 491ce603ae3ffadf4e548435486a0cb6679e027b Mon Sep 17 00:00:00 2001 From: yutiansut Date: Thu, 25 Jul 2019 04:56:27 +0800 Subject: [PATCH 1/5] # --- QUANTAXIS/QAARP/QAAccount.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/QUANTAXIS/QAARP/QAAccount.py b/QUANTAXIS/QAARP/QAAccount.py index 128e58914..f8fc9d6ea 100755 --- a/QUANTAXIS/QAARP/QAAccount.py +++ b/QUANTAXIS/QAARP/QAAccount.py @@ -317,7 +317,8 @@ def __init__( 'tax', # 税 'message', # 备注 'frozen', # 冻结资金. - 'direction' # 方向 + 'direction' # 方向, + 'total_frozen' ] ######################################################################## # 信息类: @@ -873,7 +874,7 @@ def daily_frozen(self): '每日交易结算时的持仓表' res_ = self.history_table.assign( date=pd.to_datetime(self.history_table.datetime) - ).set_index('date').resample('D').frozen.last().fillna(method='pad') + ).set_index('date').resample('D').total_frozen.last().fillna(method='pad') res_ = res_[res_.index.isin(self.trade_range)] return res_ @@ -1164,7 +1165,7 @@ def receive_simpledeal( ( self.frozen[code][str(trade_towards)]['avg_price'] * self.frozen[code][str(trade_towards)]['amount'] - ) + abs(raw_trade_money) + ) + abs(trade_money) ) / ( self.frozen[code][str(trade_towards)]['amount'] + trade_amount @@ -1272,6 +1273,11 @@ def receive_simpledeal( ORDER_DIRECTION.BUY_OPEN, ORDER_DIRECTION.SELL_OPEN ] else 0 + + try: + total_frozen = sum([itex.get('avg_price',0)* itex.get('amount',0) for item in ac.frozen.values() for itex in item.values()]) + except: + total_frozen = 0 self.history.append( [ str(trade_time), @@ -1287,7 +1293,8 @@ def receive_simpledeal( tax_fee, message, frozen_money, - trade_towards + trade_towards, + total_frozen ] ) return 0 From 9c633ad3f8c568d6ec96fc1960ac43e78ab19475 Mon Sep 17 00:00:00 2001 From: yutiansut Date: Thu, 25 Jul 2019 04:56:45 +0800 Subject: [PATCH 2/5] # --- QUANTAXIS/QAARP/QARisk.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/QUANTAXIS/QAARP/QARisk.py b/QUANTAXIS/QAARP/QARisk.py index a65b9933a..6fdcd0c8d 100755 --- a/QUANTAXIS/QAARP/QARisk.py +++ b/QUANTAXIS/QAARP/QARisk.py @@ -136,7 +136,7 @@ def __init__( if_fq选项是@尧提出的,关于回测的时候成交价格问题(如果按不复权撮合 应该按不复权价格计算assets) """ self.account = account - self.benchmark_code = benchmark_code # 默认沪深300 + self.benchmark_code = benchmark_code # 默认沪深300 self.benchmark_type = benchmark_type self.client = DATABASE.risk @@ -175,14 +175,14 @@ def __init__( self.market_data = market_data self.if_fq = if_fq if self.account.market_type == MARKET_TYPE.FUTURE_CN: - self.if_fq = False # 如果是期货, 默认设为FALSE + self.if_fq = False # 如果是期货, 默认设为FALSE if self.market_value is not None: if self.account.market_type == MARKET_TYPE.FUTURE_CN and self.account.allow_margin == True: print('margin!') self._assets = ( - #self.account.daily_frozen + - self.market_value.sum(axis=1) + + self.account.daily_frozen + + # self.market_value.sum(axis=1) + self.account.daily_cash.set_index('date').cash ).dropna() else: @@ -192,9 +192,9 @@ def __init__( ).fillna(method='pad') else: self._assets = self.account.daily_cash.set_index('date' - ).cash.fillna( - method='pad' - ) + ).cash.fillna( + method='pad' + ) self.time_gap = QA_util_get_trade_gap( self.account.start_date, @@ -393,8 +393,8 @@ def message(self): 'totaltimeindex': self.total_timeindex, 'ir': self.ir, 'month_profit': self.month_assets_profit.to_dict() - # 'init_assets': round(float(self.init_assets), 2), - # 'last_assets': round(float(self.assets.iloc[-1]), 2) + # 'init_assets': round(float(self.init_assets), 2), + # 'last_assets': round(float(self.assets.iloc[-1]), 2) } @property From e579d00397c830a4cfbc7df6c1287cf6d033340a Mon Sep 17 00:00:00 2001 From: yutiansut Date: Thu, 25 Jul 2019 05:05:04 +0800 Subject: [PATCH 3/5] # --- .../future_min_backtest.py" | 5 ++--- QUANTAXIS/QAARP/QAAccount.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git "a/EXAMPLE/4_\345\233\236\346\265\213\345\256\236\347\233\230\344\272\244\346\230\223/\345\233\236\346\265\213/\346\234\237\350\264\247\345\233\236\346\265\213/future_min_backtest.py" "b/EXAMPLE/4_\345\233\236\346\265\213\345\256\236\347\233\230\344\272\244\346\230\223/\345\233\236\346\265\213/\346\234\237\350\264\247\345\233\236\346\265\213/future_min_backtest.py" index 1e0c82e35..293cd0297 100755 --- "a/EXAMPLE/4_\345\233\236\346\265\213\345\256\236\347\233\230\344\272\244\346\230\223/\345\233\236\346\265\213/\346\234\237\350\264\247\345\233\236\346\265\213/future_min_backtest.py" +++ "b/EXAMPLE/4_\345\233\236\346\265\213\345\256\236\347\233\230\344\272\244\346\230\223/\345\233\236\346\265\213/\346\234\237\350\264\247\345\233\236\346\265\213/future_min_backtest.py" @@ -15,7 +15,7 @@ user = QA.QA_User(username='quantaxis', password='quantaxis') portfolio = user.new_portfolio('qatestportfolio') Account = portfolio.new_account(allow_sellopen=True, allow_margin=True, init_cash=5000, allow_t0=True, - account_cookie='future_test', market_type=QA.MARKET_TYPE.FUTURE_CN, frequence=QA.FREQUENCE.FIFTEEN_MIN) + account_cookie='future_testx', market_type=QA.MARKET_TYPE.FUTURE_CN, frequence=QA.FREQUENCE.FIFTEEN_MIN) # %% @@ -24,7 +24,7 @@ # %% rb_ds = QA.QA_fetch_future_min_adv( - 'RBL8', '2018-01-01', '2018-08-28', frequence='15min') + 'RBL8', '2019-01-01', '2019-07-20', frequence='15min') # %% @@ -106,7 +106,6 @@ def MACD_JCSC(dataframe, SHORT=12, LONG=26, M=9): res.trade_amount, res.trade_time) Account.settle() - # %% Risk = QA.QA_Risk(Account) diff --git a/QUANTAXIS/QAARP/QAAccount.py b/QUANTAXIS/QAARP/QAAccount.py index f8fc9d6ea..2ccaa181a 100755 --- a/QUANTAXIS/QAARP/QAAccount.py +++ b/QUANTAXIS/QAARP/QAAccount.py @@ -317,7 +317,7 @@ def __init__( 'tax', # 税 'message', # 备注 'frozen', # 冻结资金. - 'direction' # 方向, + 'direction', # 方向, 'total_frozen' ] ######################################################################## From b703943fb50ec3748e0fcf14f257a3290b4cfa91 Mon Sep 17 00:00:00 2001 From: yutiansut Date: Thu, 25 Jul 2019 05:12:20 +0800 Subject: [PATCH 4/5] # --- QUANTAXIS/QAARP/QAAccount.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/QUANTAXIS/QAARP/QAAccount.py b/QUANTAXIS/QAARP/QAAccount.py index 2ccaa181a..68707c12d 100755 --- a/QUANTAXIS/QAARP/QAAccount.py +++ b/QUANTAXIS/QAARP/QAAccount.py @@ -1275,8 +1275,9 @@ def receive_simpledeal( ] else 0 try: - total_frozen = sum([itex.get('avg_price',0)* itex.get('amount',0) for item in ac.frozen.values() for itex in item.values()]) - except: + total_frozen = sum([itex.get('avg_price',0)* itex.get('amount',0) for item in self.frozen.values() for itex in item.values()]) + except Exception as e: + print(e) total_frozen = 0 self.history.append( [ From c567f86929f6b52f258f45950b46f755e33f4df5 Mon Sep 17 00:00:00 2001 From: yutiansut Date: Thu, 25 Jul 2019 15:37:54 +0800 Subject: [PATCH 5/5] #bump to 1.5.6 --- QUANTAXIS/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QUANTAXIS/__init__.py b/QUANTAXIS/__init__.py index 156c0cc3f..93dfe06d7 100755 --- a/QUANTAXIS/__init__.py +++ b/QUANTAXIS/__init__.py @@ -31,7 +31,7 @@ 2017/4/8 """ -__version__ = '1.5.5' +__version__ = '1.5.6' __author__ = 'yutiansut' import argparse