Example #1
0
        private DoubleTimeSeries <TIndex> BinaryOperation(DoubleTimeSeries <TIndex> otherDoubleTimeSeries,
                                                          Func <double, double, double> selector)
        {
            if (otherDoubleTimeSeries == null)
            {
                throw new ArgumentNullException(nameof(otherDoubleTimeSeries));
            }
            if (otherDoubleTimeSeries.IsEmpty)
            {
                return(this);
            }

            if (IsEmpty)
            {
                throw new InvalidOperationException("TimeSeries is empty.");
            }

            int startTransformIndex = otherDoubleTimeSeries.Start.OffsetFrom(Start);

            if (startTransformIndex < 0)
            {
                throw new ArgumentException(
                          "DoubleTimeSeries parameter instance has indices which are non-overlapping with the indices of the current instance.");
            }

            int endTransformIndex = otherDoubleTimeSeries.End.OffsetFrom(Start);

            if (endTransformIndex > Count - 1)
            {
                throw new ArgumentException(
                          "DoubleTimeSeries parameter instance has indices which are non-overlapping with the indices of the current instance.");
            }

            var doubleArray = new double[Count];

            for (int i = 0; i < Count; i++)
            {
                if (i < startTransformIndex || i > endTransformIndex)
                {
                    doubleArray[i] = this[i];
                }
                else
                {
                    int otherIndex = i - startTransformIndex;
                    doubleArray[i] = selector(this[i], otherDoubleTimeSeries[otherIndex]);
                }
            }

            return(new DoubleTimeSeries <TIndex>(doubleArray, Start, IndicesLazy));
        }
Example #2
0
 private DoubleTimeSeries <TIndex> Add([NotNull] DoubleTimeSeries <TIndex> doubleTimeSeries)
 {
     return(BinaryOperation(doubleTimeSeries, (d1, d2) => d1 + d2));
 }
Example #3
0
 public override DoubleTimeSeries <TIndex> Build()
 {
     return(DoubleTimeSeries.FromDictionary(Data));
 }