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_PREFIX,
StopOrder, StopOrder,
StopOrderStatus, StopOrderStatus,
INTERVAL_DELTA_MAP
) )
from .template import CtaTemplate from .template import CtaTemplate
@ -221,6 +222,7 @@ class BacktestingEngine:
# Load 30 days of data each time and allow for progress update # Load 30 days of data each time and allow for progress update
progress_delta = timedelta(days=30) progress_delta = timedelta(days=30)
total_delta = self.end - self.start total_delta = self.end - self.start
interval_delta = INTERVAL_DELTA_MAP[self.interval]
start = self.start start = self.start
end = self.start + progress_delta end = self.start + progress_delta
@ -252,8 +254,11 @@ class BacktestingEngine:
progress_bar = "#" * int(progress * 10) progress_bar = "#" * int(progress * 10)
self.output(f"加载进度:{progress_bar} [{progress:.0%}]") self.output(f"加载进度:{progress_bar} [{progress:.0%}]")
start = end start = end + interval_delta
end += progress_delta end += (progress_delta + interval_delta)
if data:
print(data[0].datetime, data[-1].datetime)
self.output(f"历史数据加载完成,数据量:{len(self.history_data)}") self.output(f"历史数据加载完成,数据量:{len(self.history_data)}")
@ -354,6 +359,7 @@ class BacktestingEngine:
end_balance = 0 end_balance = 0
max_drawdown = 0 max_drawdown = 0
max_ddpercent = 0 max_ddpercent = 0
max_drawdown_duration = 0
total_net_pnl = 0 total_net_pnl = 0
daily_net_pnl = 0 daily_net_pnl = 0
total_commission = 0 total_commission = 0

View File

@ -4,8 +4,9 @@ Defines constants and objects used in CtaStrategy App.
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum 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" APP_NAME = "CtaStrategy"
STOPORDER_PREFIX = "STOP" STOPORDER_PREFIX = "STOP"
@ -44,3 +45,9 @@ class StopOrder:
EVENT_CTA_LOG = "eCtaLog" EVENT_CTA_LOG = "eCtaLog"
EVENT_CTA_STRATEGY = "eCtaStrategy" EVENT_CTA_STRATEGY = "eCtaStrategy"
EVENT_CTA_STOPORDER = "eCtaStopOrder" EVENT_CTA_STOPORDER = "eCtaStopOrder"
INTERVAL_DELTA_MAP = {
Interval.MINUTE: timedelta(minutes=1),
Interval.HOUR: timedelta(hours=1),
Interval.DAILY: timedelta(days=1),
}