示例#1
0
 public ForwardDataIndeier(DataForForward_Code dataForForward)
 {
     this.dataForForward = dataForForward;
     if (this.dataForForward.ReferedKLinePeriods.Count > 1)
     {
         List <IKLineData_Extend> indexKLines = new List <IKLineData_Extend>();
         for (int i = 0; i < this.dataForForward.ReferedKLinePeriods.Count; i++)
         {
             KLinePeriod klinePeriod = this.dataForForward.ReferedKLinePeriods[i];
             if (this.dataForForward.MainKLinePeriod == klinePeriod)
             {
                 continue;
             }
             indexKLines.Add(this.dataForForward.GetKLineData(klinePeriod));
         }
         this.klineToKlineIndeier = new KLineToKLineIndeier(dataForForward.MainKLine, indexKLines);
     }
     if (this.dataForForward.UseTickData)
     {
         int tradingDay            = dataForForward.TradingDay;
         ITickData_Extend tickData = this.dataForForward.CurrentTickData;
         this.klineToTickIndeier = new KLineToTickIndeier(tickData, dataForForward.MainKLine);
     }
     if (this.dataForForward.UseTimeLineData)
     {
         int tradingDay = dataForForward.TradingDay;
         ITimeLineData_Extend timeLineData = this.dataForForward.CurrentTimeLineData;
         this.timeToKLineIndeier = new TimeLineToKLineIndeier(dataForForward.MainKLine, timeLineData);
     }
 }
示例#2
0
        public void TestTimeLineToKLine()
        {
            string code  = "RB1710";
            int    start = 20170601;
            int    end   = 20170605;

            IDataPackage_Code datapackage = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code(code, start, end, 0, 0);
            IKLineData_Extend klineData   = datapackage.GetKLineData(KLinePeriod.KLinePeriod_1Minute);
            //IKLineData_Extend klineData = datapackage.GetKLineData(KLinePeriod.KLinePeriod_5Minute);
            IList <int>            tradingDays  = datapackage.GetTradingDays();
            ITimeLineData          timeLineData = datapackage.GetTimeLineData(tradingDays[0]);
            TimeLineToKLineIndeier indeier      = new TimeLineToKLineIndeier(klineData, timeLineData);

            int  tradingDayIndex = 0;
            bool isFirst         = true;

            for (int i = klineData.BarPos; i < klineData.Length; i++)
            {
                if (!isFirst && klineData.IsDayStart(i))
                {
                    tradingDayIndex++;
                    if (tradingDayIndex >= tradingDays.Count)
                    {
                        return;
                    }
                    timeLineData = datapackage.GetTimeLineData(tradingDays[tradingDayIndex]);
                    indeier.ChangeTradingDay(timeLineData);
                }
                isFirst          = false;
                klineData.BarPos = i;
                Console.WriteLine(klineData.Period + ":" + klineData.GetBar(i));
                int barPos = indeier.GetTimeLineBarPosIfFinished(i);
                if (barPos >= 0)
                {
                    timeLineData.BarPos = barPos;
                    Console.WriteLine("分时线:" + timeLineData.GetBar(barPos));
                }
                Assert.AreEqual(klineData.Time, timeLineData.Time);
                Assert.AreEqual(klineData.End, timeLineData.Price);
            }
        }