diff --git a/vnpy/app/cta_strategy/backtesting.py b/vnpy/app/cta_strategy/backtesting.py index f901ef19..3431a409 100644 --- a/vnpy/app/cta_strategy/backtesting.py +++ b/vnpy/app/cta_strategy/backtesting.py @@ -1,5 +1,5 @@ from collections import defaultdict -from datetime import date, datetime +from datetime import date, datetime, timedelta from typing import Callable from itertools import product from functools import lru_cache @@ -211,22 +211,44 @@ class BacktestingEngine: """""" self.output("开始加载历史数据") - if self.mode == BacktestingMode.BAR: - self.history_data = load_bar_data( - self.symbol, - self.exchange, - self.interval, - self.start, - self.end - ) - else: - self.history_data = load_tick_data( - self.symbol, - self.exchange, - self.start, - self.end - ) + if not self.end: + self.end = datetime.now() + # Load 30 days of data each time and allow for progress update + progress_delta = timedelta(days=30) + total_delta = self.end - self.start + + start = self.start + end = self.start + progress_delta + progress = 0 + + while start < self.end: + if self.mode == BacktestingMode.BAR: + data = load_bar_data( + self.symbol, + self.exchange, + self.interval, + start, + end + ) + else: + data = load_tick_data( + self.symbol, + self.exchange, + start, + end + ) + + self.history_data.extend(data) + + progress += progress_delta / total_delta + progress = min(progress, 1) + progress_bar = "#" * int(progress * 10) + self.output(f"加载进度:{progress_bar} [{progress:.0%}]") + + start = end + end += progress_delta + self.output(f"历史数据加载完成,数据量:{len(self.history_data)}") def run_backtesting(self):