From b117e84167338a0a01b3e28b37bee1f02b04b45f Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sat, 19 Oct 2019 00:04:52 +0800 Subject: [PATCH] [Mod] add default value for pre_close price if zero --- vnpy/app/cta_strategy/backtesting.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vnpy/app/cta_strategy/backtesting.py b/vnpy/app/cta_strategy/backtesting.py index 52560fb2..85758625 100644 --- a/vnpy/app/cta_strategy/backtesting.py +++ b/vnpy/app/cta_strategy/backtesting.py @@ -1099,7 +1099,12 @@ class DailyResult: inverse: bool ): """""" - self.pre_close = pre_close + # If no pre_close provided on the first day, + # use value 1 to avoid zero division error + if pre_close: + self.pre_close = pre_close + else: + self.pre_close = 1 # Holding pnl is the pnl from holding position at day start self.start_pos = start_pos