新修改了EMA的计算方法,合并线性回归率的计算。和通达信的结果一模一样
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace myEMA
{
public class myEMA
{
/// <summary>
/// Contains calculation results for EMA indicator
/// </summary>
public class EMAResult
{
public List<double> Values { get; set; }
public int StartIndexOffset { get; set; }
public double EmaR { get; set; }
}
//-------------------------------------------------------------------------------------------------------------------------------
#region 计算MYEMA
/// <summary>
/// Calculates Exponential Moving Average (EMA) indicator
/// </summary>
/// <param name="input">Input signal</param>
/// <param name="period">Number of periods</param>
/// <returns>Object containing operation results</returns>
public static EMAResult EMA(IEnumerable<double> input, int period)
{
var returnValues = new List<double>();
double multiplier = (2.0 / (period + 1));
//double initialSMA = input.Take(period).Average();
//returnValues.Add(initialSMA);
var copyInputValues = input.ToList();
for (int i = 0; i < copyInputValues.Count; i++)
{
if (i < 1)
{
var resultValue = copyInputValues[i];
returnValues.Add(resultValue);
}
else
{
var resultValue = (copyInputValues[i] * multiplier) + (1 - multiplier) * returnValues.Last();
returnValues.Add(resultValue);
}
}
var result = new EMAResult()
{
EmaR=returnValues.Last(),
Values = returnValues,
StartIndexOffset = period - 1
};
return result;
}
#endregion
public class mySlope
{
// public List<double> Values { get; set; }
public double SlopeResult { get; set; }
}
//-------------------------------------------------------------------------------------------------------------------------------
#region 计算slope
/// <summary>
/// Calculates slope()
/// </summary>
/// <param name="input">Input y_signal</param>
/// <param name="period">Number of periods</param>
/// <returns>Object containing operation results</returns>
public static mySlope Slope(IEnumerable<double> input_y, int period)
{ // var returnValues = new List<double>();
List<double> input_x = new List<double>();
for (int i = 1; i <= period; i++)
{
input_x.Add(i);
}
var copyInputValues_x = input_x.ToList();
var copyInputValues_y = input_y.ToList();
List<double> arr_xy=new List<double>();
List<double> arr_xx=new List<double>();
List<double> arr_x = new List<double>();
List<double> arr_y = new List<double>();
arr_x = copyInputValues_x;
for(int j=copyInputValues_y.Count-period;j<copyInputValues_y.Count;j++)
{
//arr_x.Add(copyInputValues_x[j]);
arr_y.Add(copyInputValues_y[j]);
}
double x_arr_dataAv = arr_x.Take(period).Average();
double y_arr_dataAv = arr_y.Take(period).Average();
for(int i=0;i<arr_x.Count;i++)
{
arr_x[i] = arr_x[i] - x_arr_dataAv;
arr_y[i] = arr_y[i] - y_arr_dataAv;
arr_xx.Add( arr_x[i] * arr_x[i]);
arr_xy.Add ( arr_y[i] * arr_x[i]);
}
double sumxx = arr_xx.Sum();
double sumxy = arr_xy.Sum();
var result = new mySlope()
{
SlopeResult = sumxy/sumxx,
// Values = returnValues,
};
return result;
}
#endregion
}
}
新修改了EMA的计算方法,合并线性回归率的计算。和通达信的结果一模一样的更多相关文章
- git 代码分支合并merge提交新修改远程以及本地分支
第一步:创建本地分支 点击右键选择TortoiseGit,选择Create Branch…,在Branch框中填写新分支的名称(若选中”switch to new branch”则直接转到新分支上,省 ...
- 11_Eclipse中演示Git版本的创建,历史版本的修改,创建分支,合并历史版本和当前版本
1 执行以下案例: 某研发团队2011年初开发了一款名为Apollo的信息系统,目前已发布v1.0版本.此项目初期已有部分基础代码, 研发团队再此基础代码上经过3个月的努力发布了一个功能相对完备 ...
- git 创建新项目,下载工程,合并和更新工程简单应用记录
以前使用SVN很顺手,现在公司使用git来管理代码,因此学习git的基本使用. 一.首先介绍下SVN和git的简单比较: SVN是使用得最多的版本控制管理工具. 1.是一个集中式的版本管理工具.所有的 ...
- CodeForces - 587E[线段树+线性基+差分] ->(线段树维护区间合并线性基)
题意:给你一个数组,有两种操作,一种区间xor一个值,一个是查询区间xor的结果的种类数 做法一:对于一个给定的区间,我们可以通过求解线性基的方式求出结果的种类数,而现在只不过将其放在线树上维护区间线 ...
- 校内模拟赛T5:连续的“包含”子串长度( nekameleoni?) —— 线段树单点修改,区间查询 + 尺取法合并
nekameleoni 区间查询和修改 给定N,K,M(N个整数序列,范围1~K,M次查询或修改) 如果是修改,则输入三个数,第一个数为1代表修改,第二个数为将N个数中第i个数做修改,第三个数为修改成 ...
- HNCU1324:算法2-2:有序线性表的有序合并(线性表)
http://hncu.acmclub.com/index.php?app=problem_title&id=111&problem_id=1324 题目描述 已知线性表 LA 和 L ...
- git常用命令速查:创建,修改提交,撤销,切换分支,合并分支,变基解决冲突
创建 $ git init #在当前目录下创建一个空的本地仓库 $ rm -rf .git #删除本地仓库 $ git add . #把当前目录下的所有文件添加到暂存区 $ git commi ...
- TX Text Control X10新特性之图像占位符合并
文档处理控件TX Text Control即将发布的X10版本,将升级重点还是放到了其比较优势的流式布局报表设计和生成上.慧都获得了来自其开发商Text Control GmbH公司的一手资料,迫不及 ...
- luogu P4095 [HEOI2013]Eden 的新背包问题 多重背包 背包的合并
LINK:Eden 的新背包问题 就是一个多重背包 每次去掉一个物品 询问钱数为w所能买到的最大值. 可以对于每次Q暴力dp 利用单调队列优化多重背包 这样复杂度是Qnm的. 发现过不了n==10的点 ...
随机推荐
- win平台下, 检测网络是否连接最好的办法
[Delphi]检查URL是否有效的函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 function CheckUr ...
- centos 6.5 安装weixin
下载cpanm wget http://xrl.us/cpanm --no-check-certificate -O /sbin/cpanm && chmod +x /sbin/cpa ...
- cognos启动报错
[ ERROR ] Content Manager is unable to process your request because an unexpected event occurred in ...
- 学习C++所需看的书和顺序
初学: <C++ 编程思想> <C++ Primer><The C++ Programming Language> 提高: <C++ 的发展与演化> & ...
- Poetize6: Acting Cute
3042: Acting Cute Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 59 Solved: 36[Submit][Status] Des ...
- nginx第三方模块---nginx-sticky-module的使用(基于cookie的会话保持)
目前的项目网站架构中使用了F5和nginx,F5用来做负载均衡,nginx只用作反向代理服务器.最近应客户的要求准备去掉F5,使用软负载.大家都知道nginx抗并发能力强,又可以做负载均衡,而且使用n ...
- 【转】Android 菜单(OptionMenu)大全 建立你自己的菜单--不错
原文网址:http://www.cnblogs.com/salam/archive/2011/04/04/2005329.html 菜单是用户界面中最常见的元素之一,使用非常频繁,在Android中, ...
- 数据结构(块状链表):COGS 1689. [HNOI2010]Bounce 弹飞绵羊
时间限制:1 s 内存限制:259 MB [题目描述] 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地 ...
- WPF之插件开发
一:解决方案管理器截图 效果图: 二:简单功能说明 IMsg定义了一个接口,MYPlugin1实现接口功能,”插件式开发“实现程序运行时再调用非本身引用的dll文件,调用该dll的方法实现功能 三:I ...
- Ubuntu 14.04 dnw配置
之前写的Ubuntu嵌入式环境搭建没有讲怎么配置dnw下载工具,使用dnw还得用红帽,今天配置好了ubuntu下的dnw,记录一下 首先先下载dnw的源码,这是我上传的提供给大家下载:http://p ...