This commit is contained in:
vn.py 2019-11-07 16:23:33 +08:00
parent cb835d5932
commit 09adbf5cf0
2 changed files with 16 additions and 3 deletions

View File

@ -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

View File

@ -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),
}