我在玩下面的 ActiveQuant FinancialLibrary SimpleMovingAverage 函数 SMA():
下面的算法是否有错误,它通过“展望未来”来计算平均值(就像 i < (period + skipdays) 一样)?
public static double SMA(int period, double[] vals, int skipdays) {
double value = 0.0;
for (int i = skipdays; i < (period + skipdays); i++) {
value += vals[i];
}
value /= (double) period;
return value;
}
for 循环可以替换为下面的循环,它向后看。
for (int i = skipdays - period; i < skipdays; i++) {
value += vals[i];
}
我错过了什么吗?