Example #1
0
        // public static IList<double> Decompress(this ISecurity sec, IReadOnlyList<double> data, IMemoryManagement mm = null,
        //                                         IReadOnlyList<double> increment = null)
        // {
        //     return Decompress(sec.P)
        // }

        public static IList <double> Decompress <T>(IReadOnlyList <T> originalBars, Interval curInterval,
                                                    IReadOnlyList <double> data, IReadOnlyList <double> increment,
                                                    Interval dataInterval, IReadOnlyList <T> compressedBars = null,
                                                    IMemoryManagement mm = null)
            where T : class, IBaseBar
        {
            if (originalBars == null)
            {
                throw new ArgumentNullException(nameof(originalBars));
            }

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var count = originalBars.Count;

            if (compressedBars == null)
            {
                compressedBars = BarUtils.CompressTo(originalBars, dataInterval, curInterval);
            }

            var newBars           = mm?.GetArray <double>(count) ?? new double[count];
            var dataIntervalShift = dataInterval.Shift;
            var shift             = (dataIntervalShift - curInterval.Shift).Ticks;
            var step  = curInterval.Shift.Ticks;
            var steps = dataIntervalShift.Ticks / step;

            var k     = -1;
            var ticks = 0L;

            for (var i = 0; i < originalBars.Count; i++)
            {
                var bar = originalBars[i];
                var t   = bar.Ticks;
                while (t >= ticks + shift && k < data.Count - 1)
                {
                    var index = Math.Min(++k + 1, compressedBars.Count - 1);
                    ticks = compressedBars[index].Ticks;
                }

                var curStep = (ticks - t - shift) / step + 1;
                var ci      = Math.Max(k, 0);
                newBars[i] = data[ci] - increment[ci] * ((double)curStep / steps + 2);
            }

            return(newBars);
        }
Example #2
0
            public ISecurity CompressTo(Interval interval, int shift, int adjustment, int adjShift)
            {
                var bars = BarUtils.CompressTo(Bars, interval, IntervalInstance, 0, shift, adjustment, adjShift);

                return(CompressTo(interval, bars));
            }