From e29345503b0d5652908371d45f2874af4b00de08 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 15 Feb 2019 16:05:34 +0800 Subject: [PATCH] [Fix] bug in calculating daily result of cta backtesting --- vnpy/app/cta_strategy/backtesting.py | 6 ++++-- vnpy/trader/database.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/vnpy/app/cta_strategy/backtesting.py b/vnpy/app/cta_strategy/backtesting.py index 1326a2a7..a4bd35cd 100644 --- a/vnpy/app/cta_strategy/backtesting.py +++ b/vnpy/app/cta_strategy/backtesting.py @@ -365,10 +365,10 @@ class BacktestingEngine: self.output(f"总收益率:\t{total_return:,.2f}%") self.output(f"年化收益:\t{annual_return:,.2f}%") - self.output(f"最大回撤: \t{max_drawdown:,.2f}%") + self.output(f"最大回撤: \t{max_drawdown:,.2f}") self.output(f"百分比最大回撤: {max_ddpercent:,.2f}%") - self.output(f"总盈亏:\t{total_net_pnl:,.2f}%") + self.output(f"总盈亏:\t{total_net_pnl:,.2f}") self.output(f"总手续费:\t{total_commission:,.2f}") self.output(f"总滑点:\t{total_slippage:,.2f}") self.output(f"总成交金额:\t{total_turnover:,.2f}") @@ -846,6 +846,8 @@ class DailyResult: slippage: float, ): """""" + self.pre_close = pre_close + # Holding pnl is the pnl from holding position at day start self.start_pos = start_pos self.end_pos = start_pos diff --git a/vnpy/trader/database.py b/vnpy/trader/database.py index 97027e9d..aa44a79f 100644 --- a/vnpy/trader/database.py +++ b/vnpy/trader/database.py @@ -45,7 +45,7 @@ class DbBarData(Model): db_bar.symbol = bar.symbol db_bar.exchange = bar.exchange.value db_bar.datetime = bar.datetime - db_bar.interval = bar.interval + db_bar.interval = bar.interval.value db_bar.volume = bar.volume db_bar.open_price = bar.open_price db_bar.high_price = bar.high_price