示例#1
0
        static public IQuoteCapture Uncompress(IQuoteCapture qc)
        {
            if (qc == null)
            {
                throw new ArgumentNullException();
            }

            IQuoteCapture result = new QuoteCapture(qc.Symbol);

            if (qc.Count == 0)
            {
                return(result);
            }

            //qc中至少有1个数据
            bool isSegment = false;

            result.Add(qc.FirstTime, qc.Price[0]);

            //true则认为此时在处理分段 每处理完一次分段时置为false
            isSegment = true;
            for (var i = 1; i < qc.Count; ++i)
            {//
             //通常NO_USED_PRICE不会被使用

                if (qc.Price[i] == NO_USED_PRICE && isSegment)
                {//这是重复数据 要展开
                    var endTime    = qc.Time[i];
                    var endPrice   = qc.Price[i];
                    var startTime  = qc.Time[i - 1];
                    var startPrice = qc.Price[i - 1];

                    var j = startTime + MIN_INTERVAL;
                    //用startPrice生成start到end之间的数据
                    while (j < endTime)
                    {
                        result.Add(j, startPrice);
                        j += MIN_INTERVAL;
                    }
                    //生成end数据(endtime 大则代表是正确的分段 小则意味不正确的分段 插入原来的数据
                    result.Add(endTime, endTime > startTime ? startPrice : endPrice);
                    //分段解压缩结束
                    isSegment = false;
                }
                else//非重复数据或者数据起始点 直接插入
                {
                    result.Add(qc.Time[i], qc.Price[i]);
                    isSegment = true;
                }
            }
            return(result);
        }
示例#2
0
        static public IQuoteCapture Compress(IQuoteCapture qc)
        {
            if (qc == null)
            {
                throw new ArgumentNullException();
            }

            IQuoteCapture result = new QuoteCapture(qc.Symbol);

            if (qc.Count == 0)
            {
                return(result);
            }


            //此时qc有值 先插入一个数据
            result.Add(qc.Time[0], qc.Price[0]);
            bool tail = false;

            for (int i = 1; i < qc.Count; i++)
            {
                var time  = qc.Time[i];
                var price = qc.Price[i];

                var lastTime  = qc.Time[i - 1];
                var lastPrice = qc.Price[i - 1];

                if (time - lastTime == MIN_INTERVAL && price == lastPrice)
                {//价格重复且时间递增那么该数据可以压缩
                    tail = true;
                }
                else
                {//本次数据不能被压缩那么把该数据当作分段新的起始点
                    //添加上一个分段的末尾如果分段数据只有1个那么不需要添加结尾
                    //[start: price, start+1:price,..., end:price]=>[start : price, end:-1]
                    if (tail)
                    {
                        result.Add(lastTime, NO_USED_PRICE);
                    }
                    //分段新的起始点
                    result.Add(time, price);
                    tail = false;
                }
            }
            //可能qc末尾是个分段但是此时还没能添加分段尾
            if (tail)
            {
                result.Add(qc.Time.Last(), NO_USED_PRICE);
            }

            return(result);
        }
示例#3
0
        public IQuoteCapture Distinct()
        {
            var result = new QuoteCapture(this.Symbol);

            if (this.Count == 0)
            {
                return(result);
            }
            for (var i = 0; i < this.Count; i++)
            {
                result.AddMonotonic(this.Time[i], this.Price[i], this.Volume[i]);
            }

            return(result);
        }
示例#4
0
        public virtual IQuoteCapture Extract(int sindex, int eindex)
        {
            if (sindex < 0 || eindex > this.Count - 1 || eindex < sindex)
            {
                throw new ArgumentException(string.Format("Function {0} sindex: {1}, eindex: {2}, Count: {3}",
                                                          "Extract", sindex, eindex, this.Count));
            }

            int num   = eindex - sindex + 1;
            var quote = new QuoteCapture(Symbol);

            quote.Time.AddRange(Time.GetRange(sindex, num));
            quote.Price.AddRange(Price.GetRange(sindex, num));
            quote.Volume.AddRange(Volume.GetRange(sindex, num));
            return(quote);
        }
示例#5
0
        public virtual IQuoteCapture Extract(long stime, long etime)
        {
            var q = new QuoteCapture(this.Symbol);

            if (this.Count == 0 || stime > etime || stime > this.LastTime || etime < this.FirstTime)
            {
                return(q);
            }

            int sIndex = General.BinarySearch(Time, 0, Time.Count - 1, stime, true);

            if (sIndex < 0)
            {
                sIndex++;
            }
            else if (Time[sIndex] != stime)
            {
                sIndex++;
                if (sIndex > Time.Count - 1)
                {
                    return(q);
                }
            }

            int eIndex = General.BinarySearch(Time, 0, Time.Count - 1, etime, true);

            if (eIndex == -1)
            {
                eIndex = Time.Count - 1;
            }

            if (sIndex > eIndex)
            {
                return(q);
            }

            return(Extract(sIndex, eIndex));
        }