股票价格的简单移动平均线
我正在使用下面的 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];
}
我错过了什么吗?
I was playing with ActiveQuant FinancialLibrary SimpleMovingAverage function SMA() below:
Is there an error in the algo below, where it calculates the average by looking "into the future" ( as it does 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;
}
The for loop can be replaced with that below, where it looks backward.
for (int i = skipdays - period; i < skipdays; i++) {
value += vals[i];
}
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看没有错误。该算法正确计算了从索引
skipdays
(含)到索引skipdays + period
(不包括)的数据数组的平均值,其中period > 为 1。 0 。
也许你需要重新表述这个问题。
I see no error. The algorithm correctly computes the mean value of the data array from index
skipdays
(inclusive) to indexskipdays + period
(exclusive) forperiod > 0
.Perhaps you need to rephrase the question.