3c400d7cbf5d783a287ae08719fa95c89838351e,QUANTAXIS/QABacktest/QABacktest.py,QA_Backtest,__sync_order_LM,#QA_Backtest#Any#Any#Any#Any#Any#,464

Before Change


                    self.account.order_queue[self.account.order_queue["order_id"] ==
                                             order_id_]["amount"] -= market_message_["body"]["bid"]["amount"]
        else:
            QA_util_log_info(
                "EventEngine Warning: Unknown type of order event in  %s" % str(self.now))

    def __QA_backtest_send_bid(self, __bid, __market=None):
        __message = self.market.receive_bid(__bid, __market)
        if __bid.towards == 1:

After Change


                            order_.to_df())

            else:
                self.__QA_backtest_log_info(self, "Order Event Warning:%s in %s" %
                                            (event_, str(self.now)))

        elif event_ in ["wait", "live"]:
            // 订单存活 不会导致任何状态改变
            pass
        elif event_ in ["cancel_order"]:  // 订单事件:主动撤单
            // try:
            assert isinstance(order_id_, str)
            self.account.order_queue.loc[self.account.order_queue["order_id"]
                                         == order_id_, "status"] = 400  // 注销事件
            if order_.towards is 1:
                // 多单 撤单  现金增加
                self.account.cash_available += self.account.order_queue.query("order_id=="order_id_"")[
                    "amount"] * self.account.order_queue.query("order_id=="order_id_"")["price"]

            elif order_.towards is -1:
                // 空单撤单 可卖数量增加
                self.account.sell_available[order_.code] += self.account.order_queue.query(
                    "order_id=="order_id_"")["price"]
        elif event_ in ["daily_settle"]:  // 每日结算/全撤/把成交的买入/卖出单标记为500 同时结转

            // 买入
            
            每日结算流程
            - 同步实际的现金和仓位
            - 清空留仓单/未成功的订单
            

            self.account.cash_available = self.account.cash[-1]
            self.account.sell_available = pd.DataFrame(self.account.hold[1::], columns=self.account.hold[0]).set_index(
                "code", drop=False)["amount"].groupby("code").sum()

            self.account.order_queue = pd.DataFrame()

            self.account_d_key.append(self.today)

            if len(self.account.hold) > 1:

                self.account_d_value.append(self.account.cash[-1] + sum([self.QA_backtest_get_market_data_bar(
                    self, self.account.hold[i][1], self.now, if_trade=False).close[0] * float(self.account.hold[i][3])
                    for i in range(1, len(self.account.hold))]))
            else:
                self.account_d_value.append(self.account.cash[-1])
        elif event_ in ["t_0"]:
            
            T+0交易事件

            同步t+0的账户状态 /允许卖出
            
            self.account.cash_available = self.account.cash[-1]
            self.account.sell_available = pd.DataFrame(self.account.hold[1::], columns=self.account.hold[0]).set_index(
                "code", drop=False)["amount"].groupby("code").sum()

        elif event_ in ["trade"]:
            // try:
            assert isinstance(order_, QA_QAMarket_bid)
            assert isinstance(order_id_, str)
            assert isinstance(trade_id_, str)
            assert isinstance(market_message_, dict)
            if order_.towards is 1:
                // 买入
                // 减少现金
                order_.trade_id = trade_id_
                order_.transact_time = self.now
                order_.amount -= market_message_["body"]["bid"]["amount"]

                if order_.amount == 0:  // 完全交易
                    // 注销(成功交易)["买入单不能立即结转"]
                    self.account.order_queue.loc[self.account.order_queue["order_id"]
                                                 == order_id_, "status"] = 200

                elif order_.amount > 0:
                    // 注销(成功交易)
                    self.account.order_queue.loc[self.account.order_queue["order_id"]
                                                 == order_id_, "status"] = 203
                    self.account.order_queue.query("order_id=="order_id_"")[
                        "amount"] -= market_message_["body"]["bid"]["amount"]
            elif order_.towards is -1:
                // self.account.sell_available[order_.code] -= market_message_[
                //    "body"]["bid"]["amount"]
                // 当日卖出的股票 可以继续买入/ 可用资金增加(要减去手续费)
                self.account.cash_available += market_message_["body"]["bid"]["amount"] * market_message_[
                    "body"]["bid"]["price"] - market_message_["body"]["fee"]["commission"]
                order_.trade_id = trade_id_
                order_.transact_time = self.now
                order_.amount -= market_message_["body"]["bid"]["amount"]
                if order_.amount == 0:
                    // 注销(成功交易)
                    self.account.order_queue.loc[self.account.order_queue["order_id"]
                                                 == order_id_, "status"] = 200
                else:
                    // 注销(成功交易)
                    self.account.order_queue.loc[self.account.order_queue["order_id"]
                                                 == order_id_, "status"] = 203
                    self.account.order_queue[self.account.order_queue["order_id"] ==
                                             order_id_]["amount"] -= market_message_["body"]["bid"]["amount"]
        else:
            self.__QA_backtest_log_info(self,
                                        "EventEngine Warning: Unknown type of order event in  %s" % str(self.now))

    def __QA_backtest_send_bid(self, __bid, __market=None):
        __message = self.market.receive_bid(__bid, __market)
        if __bid.towards == 1:
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 5

Non-data size: 5

Instances


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3c400d7cbf5d783a287ae08719fa95c89838351e
Time: 2017-10-04
Author: yutiansut@qq.com
File Name: QUANTAXIS/QABacktest/QABacktest.py
Class Name: QA_Backtest
Method Name: __sync_order_LM


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3c400d7cbf5d783a287ae08719fa95c89838351e
Time: 2017-10-04
Author: yutiansut@qq.com
File Name: QUANTAXIS/QABacktest/QABacktest.py
Class Name: QA_Backtest
Method Name: __QA_backtest_send_bid


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3c400d7cbf5d783a287ae08719fa95c89838351e
Time: 2017-10-04
Author: yutiansut@qq.com
File Name: QUANTAXIS/QABacktest/QABacktest.py
Class Name: QA_Backtest
Method Name: __sync_order_LM


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3c400d7cbf5d783a287ae08719fa95c89838351e
Time: 2017-10-04
Author: yutiansut@qq.com
File Name: QUANTAXIS/QABacktest/QABacktest.py
Class Name: QA_Backtest
Method Name: load_strategy


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3c400d7cbf5d783a287ae08719fa95c89838351e
Time: 2017-10-04
Author: yutiansut@qq.com
File Name: QUANTAXIS/QABacktest/QABacktest.py
Class Name: QA_Backtest
Method Name: __QA_backtest_start


Project Name: QUANTAXIS/QUANTAXIS
Commit Name: 3c400d7cbf5d783a287ae08719fa95c89838351e
Time: 2017-10-04
Author: yutiansut@qq.com
File Name: QUANTAXIS/QABacktest/QABacktest.py
Class Name: QA_Backtest
Method Name: __end_of_backtest