public static DateTime MakeDateByNight(DateTime tradeDate, TimeSlice slice) { DateTime preTradingDay = TradingDayHelper.GetPreTradingDay(tradeDate); DateTime secondDayofPreTradingDay = preTradingDay.AddDays(1); return(TradingDayHelper.GetNaturalDateTime(slice.EndTime, tradeDate, preTradingDay, secondDayofPreTradingDay)); }
static List <DateTimeSlice> CreateDateTimeSlice(DateTime tradingday, List <TimeSlice> lsttimeslice) { DateTime pretradingday1 = TradingDayHelper.GetPreTradingDay(tradingday); DateTime pretradingday2 = pretradingday1.AddDays(1).Date; List <DateTimeSlice> lstslice = new List <DateTimeSlice>(lsttimeslice.Count); foreach (TimeSlice timeslice in lsttimeslice) { lstslice.Add(new DateTimeSlice() { BeginTime = YfTimeHelper.JoinDateTime(tradingday, pretradingday1, pretradingday2, timeslice.BeginTime), EndTime = YfTimeHelper.JoinDateTime(tradingday, pretradingday1, pretradingday2, timeslice.EndTime) }); } return(lstslice); }
// 根据配置的参数来设置策略截止期限 private void setupDeadline() { DateTime preDay = TradingDayHelper.GetPreTradingDay(TradingDate); _deadlineWatching = UtilsEx.CalcDeadline(TradingDate, preDay, _tradeSlices, UtilsEx.DeadlineDir.ByBegin, DurationWatchChangeInHours * 60); _deadlineStopRunningIfPositionEmpty = UtilsEx.CalcDeadline(TradingDate, preDay, _tradeSlices, UtilsEx.DeadlineDir.ByEnd, DurationTerminalRunningIfPositionEmptyInHours * 60); _deadlineUnconditionLiquidate = UtilsEx.CalcDeadline(TradingDate, preDay, _tradeSlices, UtilsEx.DeadlineDir.ByEnd, DurationUnconditionLiquidateInMinutes); _deadlineTryLiquidate = UtilsEx.CalcDeadline(TradingDate, preDay, _tradeSlices, UtilsEx.DeadlineDir.ByEnd, DurationTryLiquidateInHours * 60); _timerWatching = new DeadlineTimer(_deadlineWatching, onDeadlineWatchingTicking, onDeadlineWatchingHit); _timerStopRunning = new DeadlineTimer(_deadlineStopRunningIfPositionEmpty, null, onDeadlineStopRunningHit); _timerTryLiquidate = new DeadlineTimer(_deadlineTryLiquidate, null, onDeadlineTryLiquidateHit); _timerUnconditionLiquidate = new DeadlineTimer(_deadlineUnconditionLiquidate, null, onDeadlineUnconditionLiquidateHit); Print("截止时间->观察: " + _deadlineWatching); Print("截止时间->平仓停止策略运行如果距离收盘时间小于" + DurationTerminalRunningIfPositionEmptyInHours + ": " + _deadlineStopRunningIfPositionEmpty); Print("截止时间->无条件平仓如果距离收盘时间小于" + DurationUnconditionLiquidateInMinutes + ": " + _deadlineUnconditionLiquidate); Print("截止时间->尝试平仓如果距离收盘时间小于" + DurationTryLiquidateInHours + ": " + _deadlineTryLiquidate); }