What is the fastest library/algorithm for calculating simple moving average? I wrote my own, but it takes too long on 330 000 items decimal dataset.
If the data is static, you can preprocess the array to make moving average queries very fast:
decimal[] GetCSum(decimal[] data) {
decimal csum[] = new decimal[data.Length];
decimal cursum = 0;
for(int i=0; i
Now the moving average calculation is easy and fast:
decimal CSumMovingAverage(decimal[] csum, int period, int ii) {
if(period == 0 || ii <= period)
return -1;
return csum[ii] - csum[ii - period];
}