private static void setEndAdjustInfo(TickInfo_Period period, TickData data, int countEverySecond) { TickPeriodAdjustInfo adjustInfo = period.adjustInfo; int endIndex = period.EndIndex; int endRepeatIndex = FindEndTimeIndex(period, data); if (endRepeatIndex > 0) { int endRepeatTimes = FindEndRepeatTimes(endRepeatIndex, data); if (endRepeatTimes > countEverySecond) { adjustInfo.EndRepeatIndex = endRepeatIndex; adjustInfo.EndRepeatTimes = endRepeatTimes; adjustInfo.EndRepeat = true; } } double time = Math.Round(period.EndTime + data.TradingDay, 6); TimeSpan span = TimeUtils.Substract(data.arr_time[endIndex], time); int timeDif = span.Minutes * 60 + span.Seconds; //收盘晚收超过1分钟,认为该收盘时间可能有误 if (timeDif > 60) { adjustInfo.EndErrorData = true; } adjustInfo.EndOffset = timeDif; }
/// <summary> /// 调整规则: /// 1.如果该开始和结束 /// /// 逻辑: /// 1.是否有repeat,如果没有repeat直接移动时间 /// 2. /// </summary> /// <param name="data"></param> /// <param name="period"></param> private void Adjust(TickData data, TickInfo_Period period) { TickPeriodAdjustInfo adjustInfo = period.adjustInfo; if (!adjustInfo.StartRepeat && !adjustInfo.EndRepeat) { Adjust_NoRepeat(data, period, adjustInfo); Console.WriteLine("NoRepeat"); } else if (adjustInfo.StartRepeat && adjustInfo.EndRepeat) { Adjust_AllRepeat(data, period, adjustInfo); Console.WriteLine("AllRepeat"); } //有时间偏移,首先根据偏移位置移正,再处理repeat else if (adjustInfo.HasTimeOffset()) { Adjust_HasTimeOffsetAndRepeat(data, period, adjustInfo); Console.WriteLine("TimeOffset"); } //起始位置repeat,末尾offset,且正好合拍 else if (adjustInfo.HasRepeatOffset()) { Adjust_HasRepeatOffset(data, period, adjustInfo); } //该数据段没有偏移,只有repeat else { Adjust_NoOffsetOnlyRepeat(data, period, adjustInfo); } }
private static void setStartAdjustInfo(TickInfo_Period period, TickData data, int countEverySecond) { TickPeriodAdjustInfo adjustInfo = period.adjustInfo; int startIndex = period.StartIndex; if (period.StartTime == 0.09 || period.StartTime == 0.21) { startIndex++; adjustInfo.IsOpen = true; } int startRepeatIndex = FindStartTimeIndex(period, data, startIndex); if (startRepeatIndex >= 0) { int startRepeatTimes = FindStartRepeatTimes(startRepeatIndex, data); if (startRepeatTimes > countEverySecond) { adjustInfo.StartRepeatIndex = startRepeatIndex; adjustInfo.StartRepeatTimes = startRepeatTimes; adjustInfo.StartRepeat = true; } } double time = Math.Round(period.StartTime + data.TradingDay, 6); TimeSpan span = TimeUtils.Substract(data.arr_time[startIndex], time); int timeDif = span.Minutes * 60 + span.Seconds; //开盘提前超过1分钟,认为该开盘时间可能有误 if (timeDif < -60) { adjustInfo.StartErrorData = true; } adjustInfo.StartOffset = timeDif; }
/// <summary> /// 例子: /// 20071017 m05 (13:30:00一共差不多70个) /// 2007-10-17,13:30:00,3226,502,459820,46,3226,10,0,0,0,0,3227,183,0,0,0,0,S /// 2007-10-17,13:30:00,3226,26,459846,-6,3225,789,0,0,0,0,3226,18,0,0,0,0,S /// ... /// 2007-10-17,13:30:00,3222,260,463172,-58,3222,1,0,0,0,0,3225,77,0,0,0,0,S /// 2007-10-17,13:30:00,3223,6,463178,-2,3223,1,0,0,0,0,3224,1,0,0,0,0,B /// ... /// 2007-10-17,14:59:15,3203,48,756442,-10,3202,528,0,0,0,0,3203,43,0,0,0,0,B /// </summary> /// <param name="data"></param> /// <param name="period"></param> /// <param name="adjustInfo"></param> private void Adjust_HasRepeatOffset(TickData data, TickInfo_Period period, TickPeriodAdjustInfo adjustInfo) { if (adjustInfo.StartRepeat) { AdjustTime(data, period.StartIndex, period.EndIndex, -adjustInfo.EndOffset); SpreadRepeatBackward(data, period, adjustInfo.StartRepeatIndex, adjustInfo.StartRepeatIndex + adjustInfo.StartRepeatTimes - 1); } else { AdjustTime(data, period.StartIndex, period.EndIndex, -adjustInfo.StartOffset); SpreadRepeatForward(data, period, adjustInfo.EndRepeatIndex, adjustInfo.EndRepeatIndex + adjustInfo.EndRepeatTimes - 1); } }
private void Adjust_AllRepeat(TickData data, TickInfo_Period period, TickPeriodAdjustInfo adjustInfo) { int adjustCount = AdjustPeriodStart(data, period); int startIndex = adjustInfo.StartRepeatIndex - adjustCount; int endIndex = adjustInfo.StartRepeatIndex + adjustInfo.StartRepeatTimes - 1; SpreadRepeatForward(data, period, startIndex, endIndex); adjustCount = AdjustPeriodEnd(data, period); startIndex = adjustInfo.EndRepeatIndex - adjustCount; endIndex = adjustInfo.EndRepeatIndex + adjustInfo.EndRepeatTimes - 1; SpreadRepeatBackward(data, period, startIndex, endIndex); }
private void Adjust_NoRepeat(TickData data, TickInfo_Period period, TickPeriodAdjustInfo adjustInfo) { if (adjustInfo.HasTimeOffset()) { AdjustTime(data, period.StartIndex, period.EndIndex, -adjustInfo.GetTimeOffset()); } int adjustCount = AdjustPeriodStart(data, period); if (adjustCount > 2) { int startIndex = adjustInfo.IsOpen ? period.StartIndex + 1 : period.StartIndex; int endIndex = startIndex + adjustCount - 1; SpreadRepeatForward(data, period, startIndex, endIndex); } adjustCount = AdjustPeriodEnd(data, period); if (adjustCount > 2) { int startIndex = period.EndIndex - adjustCount + 1; int endIndex = period.EndIndex; SpreadRepeatBackward(data, period, startIndex, endIndex); } }
private void Adjust_NoOffsetOnlyRepeat(TickData data, TickInfo_Period period, TickPeriodAdjustInfo adjustInfo) { //不设置偏移,直接调整 int adjustCount = AdjustPeriodStart(data, period); if (adjustInfo.StartRepeat) { int startIndex = adjustInfo.StartRepeatIndex - adjustCount; int endIndex = adjustInfo.StartRepeatIndex + adjustInfo.StartRepeatTimes - 1; SpreadRepeatForward(data, period, startIndex, endIndex); } adjustCount = AdjustPeriodEnd(data, period); if (adjustInfo.EndRepeat) { int startIndex = adjustInfo.EndRepeatIndex - adjustInfo.EndRepeatTimes + 1; int endIndex = adjustInfo.EndRepeatIndex + adjustCount; SpreadRepeatBackward(data, period, startIndex, endIndex); } }
/// <summary> /// 既有偏移又有repeat的情况 /// </summary> /// <param name="data"></param> /// <param name="period"></param> /// <param name="adjustInfo"></param> private void Adjust_HasTimeOffsetAndRepeat(TickData data, TickInfo_Period period, TickPeriodAdjustInfo adjustInfo) { AdjustTime(data, period.StartIndex, period.EndIndex, -adjustInfo.GetTimeOffset()); AdjustPeriodStart(data, period); if (adjustInfo.StartRepeat) { int startIndex = adjustInfo.StartRepeatIndex; int endIndex = adjustInfo.StartRepeatIndex + adjustInfo.StartRepeatTimes - 1; //如果调整后向前移动的空间能够容纳下repeat,则向前填充 if (-adjustInfo.GetTimeOffset() * 2 > adjustInfo.StartRepeatTimes) { SpreadRepeatBackward(data, period, startIndex, endIndex); } else { int mIndex = startIndex - adjustInfo.GetTimeOffset() * 2 - 4; SpreadRepeatBackward(data, period, startIndex, mIndex); SpreadRepeatForward(data, period, mIndex, endIndex); } } AdjustPeriodEnd(data, period); if (adjustInfo.EndRepeat) { int startIndex = adjustInfo.EndRepeatIndex; int endIndex = adjustInfo.EndRepeatIndex + adjustInfo.EndRepeatTimes - 1; //如果调整后向前移动的空间能够容纳下repeat,则向前填充 if (adjustInfo.GetTimeOffset() * 2 > adjustInfo.EndRepeatTimes) { SpreadRepeatForward(data, period, startIndex, endIndex); } else { int mIndex = endIndex - adjustInfo.GetTimeOffset() * 2 + 4; SpreadRepeatBackward(data, period, startIndex, mIndex); SpreadRepeatForward(data, period, mIndex, endIndex); } } }