我知道,这只是直接回答了问题,但我正在寻找一个非常相似的解决办法,从一个小的时期到一个更长的时期(5、10、15、30)对库存/密码货币的中值数据进行汇总。 你们只能从现在的十分钟回来,因为总合时期的顶点是稳定的。 你们还必须看到,在清单的开始和结束时,有足够的数据来全面标明较长时间。 有鉴于此,我提出的解决办法如下。 (它假设,如原产地所示,较小时期的蜡dle按装饰时序排列)
public class Candle
{
public long Id { get; set; }
public Period Period { get; set; }
public DateTime Timestamp { get; set; }
public double High { get; set; }
public double Low { get; set; }
public double Open { get; set; }
public double Close { get; set; }
public double BuyVolume { get; set; }
public double SellVolume { get; set; }
}
public enum Period
{
Minute = 1,
FiveMinutes = 5,
QuarterOfAnHour = 15,
HalfAnHour = 30
}
private List<Candle> AggregateCandlesIntoRequestedTimePeriod(Period rawPeriod, Period requestedPeriod, List<Candle> candles)
{
if (rawPeriod != requestedPeriod)
{
int rawPeriodDivisor = (int) requestedPeriod;
candles = candles
.GroupBy(g => new { TimeBoundary = new DateTime(g.Timestamp.Year, g.Timestamp.Month, g.Timestamp.Day, g.Timestamp.Hour, (g.Timestamp.Minute / rawPeriodDivisor) * rawPeriodDivisor , 0) })
.Where(g => g.Count() == rawPeriodDivisor )
.Select(s => new Candle
{
Period = requestedPeriod,
Timestamp = s.Key.TimeBoundary,
High = s.Max(z => z.High),
Low = s.Min(z => z.Low),
Open = s.First().Open,
Close = s.Last().Close,
BuyVolume = s.Sum(z => z.BuyVolume),
SellVolume = s.Sum(z => z.SellVolume),
})
.OrderBy(o => o.Timestamp)
.ToList();
}
return candles;
}