namespace KLHZ.Trader.Core.Math.Declisions.Utils { public static class SignalProcessing { public static (DateTime[] timestamps, decimal[] values) InterpolateData(DateTime[] timestamps, decimal[] values, TimeSpan timeStep) { var res = new List(); var res2 = new List(); var startTime = new DateTime(timestamps[0].Year, timestamps[0].Month, timestamps[0].Day, 0, 0, 0, DateTimeKind.Utc); var dt = timestamps[0] - startTime; var totalSteps = System.Math.Ceiling((timestamps[timestamps.Length - 1] - timestamps[0]).TotalSeconds / timeStep.TotalSeconds); var deltaSeconds = System.Math.Floor(dt.TotalSeconds / timeStep.TotalSeconds); startTime = startTime.AddSeconds(deltaSeconds * timeStep.TotalSeconds); var firstBound = startTime; var secondBound = startTime + timeStep; var bound = 0; for (int i = 0; i < totalSteps; i++) { var count = 0; var sum = 0m; for (int i1 = bound; i1 < timestamps.Length; i1++) { if (timestamps[i1] > firstBound && timestamps[i1] <= secondBound) { count++; sum += values[i1]; } else if (count != 0) { bound = i1; break; } } if (count != 0) { res.Add(sum / count); res2.Add(secondBound); } else if (bound < timestamps.Length - 2) { res.Add(values[bound]); res2.Add(secondBound); } firstBound += timeStep; secondBound += timeStep; } return (res2.ToArray(), res.ToArray()); } } }