Exemplo n.º 1
0
        /// <summary>
        /// 把 count 个 Bar 合并成一个新的 Bar
        /// </summary>
        /// <param name="series"></param>
        /// <param name="inst"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static BarSeries MergeCompress(this BarSeries series, Instrument inst, long count)
        {
            if (series.Count == 0 || count < 2)
            {
                return(new BarSeries());
            }
            var  selector    = new TimeRangeSelector(inst);
            bool emitOnClose = !(series[0].Size >= QuantBoxConst.DayBarSize);

            var bars  = new BarSeries();
            Bar last  = null;
            var index = 0;

            foreach (var bar in series)
            {
                var range = selector.Get(bar.DateTime.Date);
                if (index == 0)
                {
                    last       = bar;
                    last.Size *= count;
                }
                else
                {
                    QBHelper.MergeBar(last, bar);
                }
                ++index;
                if (index == count || (emitOnClose && bar.CloseDateTime.TimeOfDay == range.CloseTime))
                {
                    bars.Add(last);
                    last  = null;
                    index = 0;
                }
            }
            return(bars);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 把 count 个 Bar 合并成一个新的 Bar
        /// </summary>
        /// <param name="series"></param>
        /// <param name="inst"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static BarSeries MergeCompress(this BarSeries series, Instrument inst, long count)
        {
            if (series.Count == 0 || count < 2)
            {
                return(new BarSeries());
            }
            var selector    = new TimeRangeSelector(inst);
            var emitOnClose = true;
            var bar         = series[0];

            if (bar.Size >= QuantBoxConst.DayBarSize)
            {
                emitOnClose = false;
            }

            var bars  = new BarSeries();
            Bar last  = null;
            var index = 0;

            for (int i = 0; i < series.Count; i++)
            {
                var range = selector.Get(series[i].DateTime.Date);
                if (index == 0)
                {
                    last       = series[i];
                    last.Size *= count;
                }
                else
                {
                    QBHelper.MergeBar(last, series[i]);
                }
                ++index;
                if (index == count || (emitOnClose && series[i].CloseDateTime.TimeOfDay == range.CloseTime))
                {
                    bars.Add(last);
                    last  = null;
                    index = 0;
                    continue;
                }
            }
            return(bars);
        }