Esempio n. 1
0
    def get_result(self, report: bool = False, **kwargs):
        """
        计算回测结果,生成回测报告

        Args:
          report(bool): 是否生成报告

          auto_open(bool): 是否让浏览器自动打开回测报告

        Return:
            Dataframe: 生成结果, 以Dataframe形式.
        """
        strategys = list(self._extensions.keys())
        end_time = datetime.now()
        """
        账户数据
        """
        account_data = self.trader.account.get_mapping("balance")
        """
        耗费时间
        """
        cost_time = f"{str(end_time.hour - self.start_datetime.hour)}" \
                    f"h {str(end_time.minute - self.start_datetime.minute)}m " \
                    f"{str(end_time.second - self.start_datetime.second)}s"
        """
        每日盈利
        """
        net_pnl = self.trader.account.get_mapping("net_pnl")
        """
        成交单数据
        """
        trade_data = list(map(dumps,
                              self.trader.traded_order_mapping.values()))
        position_data = self.trader.position_detail
        if report:
            path = render_result(self.trader.account.result,
                                 trade_data=trade_data,
                                 strategy=strategys,
                                 net_pnl=net_pnl,
                                 account_data=account_data,
                                 datetimed=end_time,
                                 position_data=position_data,
                                 cost_time=cost_time,
                                 **kwargs)
            print(f"请复制下面的路径到浏览器打开----> \n {path}")

        return self.trader.account.result, list(
            self.trader.traded_order_mapping.values())
Esempio n. 2
0
 def get_result(self, report: bool = False, **kwargs):
     """
     计算回测结果,生成回测报告
     :param report: bool ,指定是否输出策略报告
     :param auto_open: bool, 是否让浏览器自动打开回测报告
     :param zh:bpol, 是否输出成中文报告
     """
     strategys = list(self.interface.strategy_mapping.keys())
     end_time = datetime.now()
     """
     账户数据
     """
     account_data = self.interface.account.get_mapping("balance")
     """
     耗费时间
     """
     cost_time = f"{str(end_time.hour - self.start_time.hour)}" \
                 f"h {str(end_time.minute - self.start_time.minute)}m " \
                 f"{str(end_time.second - self.start_time.second)}s"
     """
     每日盈利
     """
     net_pnl = self.interface.account.get_mapping("net_pnl")
     """
     成交单数据
     """
     trade_data = list(
         map(dumps, self.interface.traded_order_mapping.values()))
     position_data = self.interface.position_detail
     if report:
         path = render_result(self.interface.account.result,
                              trade_data=trade_data,
                              strategy=strategys,
                              net_pnl=net_pnl,
                              account_data=account_data,
                              datetimed=end_time,
                              position_data=position_data,
                              cost_time=cost_time,
                              **kwargs)
         print(f"请复制下面的路径到浏览器打开----> \n {path}")
         return path
     return self.interface.account.result