public static List <ITimeLineData> ConvertTimeLineDataList(IKLineData data, float lastEndPrice, ITradingTimeReader_Code tradingSessionReader) { List <SplitterResult> splitResult = DaySplitter.Split(data, tradingSessionReader); List <ITimeLineData> realdataList = new List <ITimeLineData>(splitResult.Count); for (int i = 0; i < splitResult.Count; i++) { SplitterResult split = splitResult[i]; int date = split.Date; int todayStartIndex = split.Index; int todayEndIndex; if (i == splitResult.Count - 1) { todayEndIndex = data.Length - 1; } else { todayEndIndex = splitResult[i + 1].Index; } int len = todayEndIndex - todayStartIndex + 1; TimeLineData r = new TimeLineData(lastEndPrice, len); r.Code = data.Code; Convert2RealData(data, todayStartIndex, todayEndIndex, r); realdataList.Add(r); } return(realdataList); }
public void TestSplit_EndInNight() { IKLineData klineData = MockDataLoader.GetKLineData("m1505", 20150105, 20150106, KLinePeriod.KLinePeriod_1Minute); IKLineData subData = klineData.Sub(0, 570); List <SplitterResult> results = DaySplitter.Split(subData, GetTradingSessionCache("m1505")); Assert.AreEqual("20150105,0", results[0].ToString()); Assert.AreEqual("20150106,225", results[1].ToString()); }
private void AssertDaySplitter(string code, int start, int end, KLinePeriod period, string fileName) { CacheUtils_TradingTime cache = GetTradingSessionCache(code); IKLineData klineData = MockDataLoader.GetKLineData(code, start, end, period); List <SplitterResult> results = DaySplitter.Split(klineData, cache); AssertUtils.AssertEqual_List <SplitterResult>(fileName, GetType(), results); //AssertUtils.PrintKLineData(klineData); //AssertUtils.PrintLineList(results); }
/// <summary> /// 将k线转换成日线 /// </summary> /// <param name="data"></param> /// <param name="targetPeriod"></param> /// <param name="timeSplit"></param> /// <returns></returns> public static IKLineData Transfer_Day(IKLineData data, KLinePeriod targetPeriod, ITradingTimeReader_Code startTimeReader) { List <SplitterResult> results = DaySplitter.Split(data, startTimeReader); List <KLineBar> charts = new List <KLineBar>(results.Count); for (int i = 0; i < results.Count; i++) { int startIndex = results[i].Index; int endIndex = (i == results.Count - 1) ? data.Length - 1 : results[i + 1].Index - 1; charts.Add(GetChart_Day(data, startIndex, endIndex)); } return(GetKLineData(data.Code, charts)); }