Пример #1
0
 public DataForForward_Code(IDataPackage_Code dataPackage, ForwardReferedPeriods referedPeriods)
 {
     this.dataPackage          = dataPackage;
     this.referedPeriods       = referedPeriods;
     this.dic_Period_KLineData = dataPackage.CreateKLineData_RealTimes(referedPeriods.UsedKLinePeriods);
     this.mainKLinePeriod      = referedPeriods.GetMinPeriod();
     this.mainKLineData        = this.dic_Period_KLineData[mainKLinePeriod];
     this.cache_TradingDay     = new CacheUtils_TradingDay(dataPackage.GetTradingDays());
 }
Пример #2
0
        private void InitStrategyExecutorInfo()
        {
            this.strategyExecutorInfo                 = new StrategyExecutorInfo(codePeriod, dataPackage.GetTradingDays().Count);
            this.strategyExecutorInfo.CurrentDay      = dataPackage.GetTradingDays()[0];
            this.strategyExecutorInfo.CurrentDayIndex = 0;

            this.tempBarFinishedArguments = new StrategyBarFinishedArguments(this.strategyExecutorInfo);
            this.tempDayFinishedArguments = new StrategyDayFinishedArguments(this.strategyExecutorInfo);
        }
Пример #3
0
        public void Load(XmlElement xmlElem)
        {
            this.dataPackage    = this.dataCenter.DataPackageFactory.CreateDataPackage_Code(xmlElem);
            this.referedPeriods = new ForwardReferedPeriods();
            this.referedPeriods.Load(xmlElem);

            this.dic_Period_KLineData = dataPackage.CreateKLineData_RealTimes(referedPeriods.UsedKLinePeriods);
            this.cache_TradingDay     = new CacheUtils_TradingDay(dataPackage.GetTradingDays());
            this.TradingDay           = int.Parse(xmlElem.GetAttribute("tradingDay"));
        }
Пример #4
0
        public HistoryDataForward_Code_TickPeriod(IDataPackage_Code dataPackage, IList <KLinePeriod> periods, KLinePeriod forwardPeriod, bool useTimeLineData)
        {
            this.allKLinePeriods = periods;
            Dictionary <KLinePeriod, IKLineData_RealTime> allKLineData = dataPackage.CreateKLineData_RealTimes(periods);
            IList <int> tradingDays = dataPackage.GetTradingDays();

            this.useTimeLineData = useTimeLineData;
            this.onBarArgument   = new ForwardOnBarArgument(barFinishedInfos);
            Init(dataPackage, allKLineData, tradingDays, forwardPeriod);
        }
Пример #5
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);
            }
        }
Пример #6
0
        public RealTimeReader_Strategy(IDataPackage_Code dataPackage, ForwardReferedPeriods referedPeriods, ForwardPeriod forwardPeriod)
        {
            this.dataPackage    = dataPackage;
            this.code           = dataPackage.Code;
            this.startDate      = dataPackage.StartDate;
            this.endDate        = dataPackage.EndDate;
            this.referedPeriods = referedPeriods;
            this.forwardPeriod  = forwardPeriod;

            this.allKLineData = new Dictionary <KLinePeriod, KLineData_RealTime>();
            for (int i = 0; i < referedPeriods.UsedKLinePeriods.Count; i++)
            {
                KLinePeriod        period             = referedPeriods.UsedKLinePeriods[i];
                IKLineData         klineData          = dataPackage.GetKLineData(period);
                KLineData_RealTime klineData_RealTime = new KLineData_RealTime(klineData);
                allKLineData.Add(period, klineData_RealTime);
            }

            IList <int> allTradingDays = dataPackage.GetTradingDays();

            if (forwardPeriod.IsTickForward)
            {
                this.klineDataForward = new HistoryDataForward_Code_TickPeriod(dataPackage, allKLineData, allTradingDays, forwardPeriod.KlineForwardPeriod);
            }
            else
            {
                KLinePeriod        mainPeriod    = forwardPeriod.KlineForwardPeriod;
                KLineData_RealTime mainKLineData = allKLineData[mainPeriod];
                this.klineDataForward = new HistoryDataForward_Code_KLinePeriod(code, mainKLineData, allKLineData);
            }

            this.klineDataForward.OnRealTimeChanged += KlineDataForward_OnRealTimeChanged;
            this.klineDataForward.OnTick            += KlineDataForward_OnTick;
            this.klineDataForward.OnBar             += KlineDataForward_OnBar;

            //this.klineDataForward = HistoryDataForwardFactory.CreateHistoryDataForward_Code(dataPackage, referedPeriods, forwardPeriod);
            //this.klineDataForward.OnTick += KlineDataForward_OnTick;
            //this.klineDataForward.OnBar += KlineDataForward_OnBar;
        }
Пример #7
0
        public void TestKLineToTick_Days()
        {
            string code  = "RB1710";
            int    start = 20170601;
            int    end   = 20170605;

            List <string>     list_OnBar  = new List <string>();
            IDataPackage_Code datapackage = DataCenter.Default.DataPackageFactory.CreateDataPackage_Code(code, start, end, 0, 0);
            IKLineData_Extend klineData   = datapackage.GetKLineData(KLinePeriod.KLinePeriod_1Minute);

            IList <int>        tradingDays = datapackage.GetTradingDays();
            ITickData          tickData    = datapackage.GetTickData(tradingDays[0]);
            KLineToTickIndeier indeier     = new KLineToTickIndeier(tickData, klineData);

            DoIndex(list_OnBar, klineData, tickData, indeier);

            for (int i = 1; i < tradingDays.Count; i++)
            {
                tickData = datapackage.GetTickData(tradingDays[i]);
                indeier.ChangeTradingDay(tickData);
                DoIndex(list_OnBar, klineData, tickData, indeier);
            }
        }
Пример #8
0
        private void Init(IDataPackage_Code dataPackage, ForwardReferedPeriods referedPeriods, ForwardPeriod forwardPeriod)
        {
            this.dataPackage    = dataPackage;
            this.referedPeriods = referedPeriods;
            this.forwardPeriod  = forwardPeriod;

            Dictionary <KLinePeriod, KLineData_RealTime> allKLineData = new Dictionary <KLinePeriod, KLineData_RealTime>();

            for (int i = 0; i < referedPeriods.UsedKLinePeriods.Count; i++)
            {
                KLinePeriod        period             = referedPeriods.UsedKLinePeriods[i];
                IKLineData         klineData          = this.dataPackage.GetKLineData(period);
                KLineData_RealTime klineData_RealTime = new KLineData_RealTime(klineData);
                allKLineData.Add(period, klineData_RealTime);
            }

            //ITimeLineData timelineData = this.dataReader.TimeLineDataReader.GetData(code, startDate);
            //this.timeLineData_RealTime = new TimeLineData_RealTime(timelineData);

            IList <int> allTradingDays = dataPackage.GetTradingDays();

            if (forwardPeriod.IsTickForward)
            {
                //this.historyDataForward = new HistoryDataForward_Code_TickPeriod(dataReader, code, allKLineData, allTradingDays, forwardPeriod.KlineForwardPeriod);
                this.historyDataForward = new HistoryDataForward_Code_TickPeriod(dataPackage, allKLineData, allTradingDays, forwardPeriod.KlineForwardPeriod);
            }
            else
            {
                KLinePeriod        mainPeriod    = forwardPeriod.KlineForwardPeriod;
                KLineData_RealTime mainKLineData = allKLineData[mainPeriod];
                this.historyDataForward = new HistoryDataForward_Code_KLinePeriod(Code, mainKLineData, allKLineData);
            }

            this.historyDataForward.OnRealTimeChanged += HistoryDataForward_OnRealTimeChanged;
            this.historyDataForward.OnTick            += KlineDataForward_OnTick;
            this.historyDataForward.OnBar             += KlineDataForward_OnBar;
        }
Пример #9
0
 public IList <int> GetTradingDays()
 {
     return(dataPackage_Code.GetTradingDays());
 }