首页 / C# / 将反向移动平均公式转换为C#
将反向移动平均公式转换为C#
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了将反向移动平均公式转换为C#,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1715字,纯文字阅读大概需要3分钟。
内容图文
![将反向移动平均公式转换为C#](/upload/InfoBanner/zyjiaocheng/664/4dc772154f2c411d98254ef36b74fd27.jpg)
我一直在绞尽脑汁尝试将这个公式转换为C#,但没有成功.
rema formula.
我擅长做杂技,但不擅长数学.
Where 0 < λ ≤ 1 is a decay factor.
When λ < 1, the exponentially weighted moving average assigns greater weights to the prices.Contrary to the regular exponential moving average that gives greater
weights to the most recent prices, the reverse exponential moving
average assigns greater weights to the oldest prices and
decreases the importance of the most recent prices.
解决方法:
高效的REMA(),带有错误检查和功能;特定于上下文的返回值
有效率吗?是的,避免重复重复的昂贵操作(或依靠编译器优化技巧)
进行错误检查?是的,对于Q / A程序几乎是必须的.
特定于上下文的?是,返回{-1. | REMA(k,lambda)},它允许调用者处理输入错误的特殊情况.
double[] fTimeSeriesPRICE; // a forward-stepping storage ( vs. a MT4 reversed-stepping model )
public double REMA( int k, double lambda )
{
if ( lambda <= 0.0 // lambda shall not fall on/under 0.0
|| lambda > 1.0 // shall not grow beyond 1.0
|| k <= 0 // depth shall not be negative or 0
)
return -1.0; // context-protecting RET value
int aCurrentPricePTR = fTimeSeriesPRICE.Length - 1;
int aMaxIterableDEPTH = Math.Min( aCurrentPricePTR, k );
double numerator = 0.0;
double denominator = 0.0; // REMA formula-expansion contains +1 at the end, never less, never negative
double lambdator = 1.0; // lambda ^ ( ( k - j ) == 0 ) == 1.0
for ( int aReverseSteppingPTR = 0;
aReverseSteppingPTR <= aMaxIterableDEPTH;
aReverseSteppingPTR++
)
{ numerator += lambdator * fTimeSeriesPRICE[aCurrentPricePTR - aReverseSteppingPTR];
denominator += lambdator;
lambdator *= lambda;
}
return numerator / denominator; // numerically fair, denominator never < +1.0
}
内容总结
以上是互联网集市为您收集整理的将反向移动平均公式转换为C#全部内容,希望文章能够帮你解决将反向移动平均公式转换为C#所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。