From 09adbf5cf05877522d8a0463c20a711f5d712d6e Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Thu, 7 Nov 2019 16:23:33 +0800 Subject: [PATCH] [Fix] close #2160 --- vnpy/app/cta_strategy/backtesting.py | 10 ++++++++-- vnpy/app/cta_strategy/base.py | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/vnpy/app/cta_strategy/backtesting.py b/vnpy/app/cta_strategy/backtesting.py index 3fbea733..b3a9bdca 100644 --- a/vnpy/app/cta_strategy/backtesting.py +++ b/vnpy/app/cta_strategy/backtesting.py @@ -25,6 +25,7 @@ from .base import ( STOPORDER_PREFIX, StopOrder, StopOrderStatus, + INTERVAL_DELTA_MAP ) from .template import CtaTemplate @@ -221,6 +222,7 @@ class BacktestingEngine: # Load 30 days of data each time and allow for progress update progress_delta = timedelta(days=30) total_delta = self.end - self.start + interval_delta = INTERVAL_DELTA_MAP[self.interval] start = self.start end = self.start + progress_delta @@ -252,8 +254,11 @@ class BacktestingEngine: progress_bar = "#" * int(progress * 10) self.output(f"加载进度:{progress_bar} [{progress:.0%}]") - start = end - end += progress_delta + start = end + interval_delta + end += (progress_delta + interval_delta) + + if data: + print(data[0].datetime, data[-1].datetime) self.output(f"历史数据加载完成,数据量:{len(self.history_data)}") @@ -354,6 +359,7 @@ class BacktestingEngine: end_balance = 0 max_drawdown = 0 max_ddpercent = 0 + max_drawdown_duration = 0 total_net_pnl = 0 daily_net_pnl = 0 total_commission = 0 diff --git a/vnpy/app/cta_strategy/base.py b/vnpy/app/cta_strategy/base.py index 5e412be9..c20295bf 100644 --- a/vnpy/app/cta_strategy/base.py +++ b/vnpy/app/cta_strategy/base.py @@ -4,8 +4,9 @@ Defines constants and objects used in CtaStrategy App. from dataclasses import dataclass, field from enum import Enum +from datetime import timedelta -from vnpy.trader.constant import Direction, Offset +from vnpy.trader.constant import Direction, Offset, Interval APP_NAME = "CtaStrategy" STOPORDER_PREFIX = "STOP" @@ -44,3 +45,9 @@ class StopOrder: EVENT_CTA_LOG = "eCtaLog" EVENT_CTA_STRATEGY = "eCtaStrategy" EVENT_CTA_STOPORDER = "eCtaStopOrder" + +INTERVAL_DELTA_MAP = { + Interval.MINUTE: timedelta(minutes=1), + Interval.HOUR: timedelta(hours=1), + Interval.DAILY: timedelta(days=1), +}