EMA指数平滑移动平均
英文参考:http://www.incrediblecharts.com/indicators/exponential_moving_average.php
Exponential moving averages are recommended as the most reliable of the basic moving average types. They provide an element of weighting, with each preceding day given progressively less weighting. Exponential smoothing avoids the problem encountered with simple moving averages, where the average has a tendency to "bark twice": once at the start of the moving average period and again in the opposite direction, at the end of the period. Exponential moving average slope is also easier to determine: the slope is always down when price closes below the moving average and always up when price is above.
Formula
To calculate an exponential moving average (EMA):
- Take today's price multiplied by an EMA%.
- Add this to yesterday's EMA multiplied by (1 - EMA%).
If we recalculate the earlier table we see that the exponential moving average presents a far smoother trend:
| Day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| Price ($) | 16 | 17 | 17 | 10 | 17 | 18 | 17 | 17 | 17 |
| 33.3% (or 1/3) EMA | 16.3 | 16.5 | 14.4 | 15.2 | 16.2 | 16.4 | 16.6 | 16.8 |
指数移动平均被认为是最可靠的基本移动平均类型。每个抽样数据都附有以一个权重值,相邻的两个权重值向前递减(也就是前一个权重值比当前权重值减一)。指数移动平均的指数平滑避免了’一般移动平均‘的某些问题,比如一般的移动平均会有“两次跳跃(bark twice)”的现象,从而扭曲数据与实际情况的符合程度。
比如:
Simple Moving Average Formula
To calculate a 5 day simple moving average ("SMA"), take the sum of the last 5 days prices and divide by 5.
| Day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| Price ($) | 16 | 17 | 17 | 10 | 17 | 18 | 17 | 17 | 17 |
| 5 Day SMA | 15.4 | 15.8 | 15.8 | 15.8 | 17.2 |
从上面的表格我们可以看到,在第9天,简单移动平均结果是17.2,与第8天的简单移动平均15.8相比有一个较大的跳跃,而第8、9两天的实际数据为17、17并没有变化。在第4天时的数据不仅仅引起当前数值上的下降,而且还对第9天的简单移动平均造成了扭曲,也就是前面说的那个条约。这就是所谓的“bark twice”。也就是说原始数据一次脉冲式跳跃,会导致后面数据的跳跃,并且两次跳跃的方向相反,从而不能很好描述原始数据的变化趋势。因此才有人提出了指数平滑移动平均线Exponential Moving Average,简称EMA。
EXPMA(Exponential Moving Average)译指数平滑移动平均线,简称EMA,
求当日价格X的N日指数平滑移动平均,在股票公式中一般表达为:EMA(X,N),其中X为当日收盘价,N为天数。它真正的公式表达是:当日指数平均值=平滑系数*(当日指数值-昨日指数平均值)+昨日指数平均值;平滑系数=2/(周期单位+1);由以上公式推导开,得到:EMA(N)=2*X/(N+1)+(N-1)*EMA(N-1)/(N+1);
可是这个公式的前提是要知道前一天的EMA,如果已知N天的价格,我想求取连续N天的EMA,怎么根据这个N个价格计算EMA呢?根据归纳推算得到公式如下:

在冈萨雷斯的《数字图像处理》第3版,10.3.7节中,使用移动平均实现对文档图像的阈值处理。在本文中的指数平滑移动平均也可以实现同样的效果,两种方法的差别没有细研究。下面是实现代码,和结果
#include <iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std; void EMA(Mat&src,int N,double b)
{
// copyMakeBorder(src,src,0,0,N,N,BORDER_REFLECT_101);
Mat initialRect=src(Rect(,,N,));
Scalar m0=mean(initialRect);
double m_last=m0[];
for(int i=;i<src.rows;i++)
{
for(int j=;j<src.cols;j++)
{
double X=double(src.at<uchar>(i,j));
double m_next=*X/(N+)+(N-)*m_last/(N+);
if(X>m_next*b)
src.at<uchar>(i,j)=;
else
src.at<uchar>(i,j)=;
m_last=m_next;
}
}
} int main()
{
Mat src=imread("D:/Qt/MyImage/Fig1049.tif",);
EMA(src,,0.7);
imshow("original image",src);
waitKey();
return ;
}
下面分别是原图像和经过EMA阈值化后的图像:


EMA指数平滑移动平均的更多相关文章
- 使用excel计算指数平滑和移动平均
指数平滑法 原数数据如下: 点击数据——数据分析 选择指数平滑 最一次平滑 由于我们选择的区域是B1:B22,第一个单元格“钢产量”,被当做标志,所以我们应该勾选标志.当我们勾选了标志后,列中的第 ...
- Holt Winter 指数平滑模型
1 指数平滑法 移动平均模型在解决时间序列问题上简单有效,但它们的计算比较难,因为不能通过之前的计算结果推算出加权移动平均值.此外,移动平均法不能很好的处理数据集边缘的数据变化,也不能应用于现有数据集 ...
- pandas 学习 第3篇:Series - 数据处理(应用、分组、滚动、扩展、指数加权移动平均)
序列内置一些函数,用于循环对序列的元素执行操作. 一,应用和转换函数 应用apply 对序列的各个元素应用函数: Series.apply(self, func, convert_dtype=True ...
- R语言与数据分析之九:时间内序列--HoltWinters指数平滑法
今天继续就指数平滑法中最复杂的一种时间序列:有增长或者减少趋势而且存在季节性波动的时间序列的预測算法即Holt-Winters和大家分享.这样的序列能够被分解为水平趋势部分.季节波动部分,因此这两个因 ...
- 转载:二次指数平滑法求预测值的Java代码
原文地址: http://blog.csdn.net/qustmeng/article/details/52186378?locationNum=4&fps=1 import java.uti ...
- 时间序列挖掘-预测算法-三次指数平滑法(Holt-Winters)——三次指数平滑算法可以很好的保存时间序列数据的趋势和季节性信息
from:http://www.cnblogs.com/kemaswill/archive/2013/04/01/2993583.html 在时间序列中,我们需要基于该时间序列当前已有的数据来预测其在 ...
- [译]如何使用Python构建指数平滑模型:Simple Exponential Smoothing, Holt, and Holt-Winters
原文连接:How to Build Exponential Smoothing Models Using Python: Simple Exponential Smoothing, Holt, and ...
- 时间序列数据的定义,读取与指数平滑(Java)
应上头的要求,需要实现以下指数平滑进行资源调度负载的预测,那就是用我最喜欢的Java做一下吧. 引用<计量经济学导论>的一句话:时间序列数据区别于横截面数据的一个明显特点是,时间序列数据集 ...
- R-三次指数平滑法实践
data <- read.csv("H://day_shuaka.csv") raw0 <- data[359:752,] raw0$weekday <- as. ...
随机推荐
- [易学易懂系列|rustlang语言|零基础|快速入门|(24)|实战2:命令行工具minigrep(1)]
[易学易懂系列|rustlang语言|零基础|快速入门|(24)|实战2:命令行工具minigrep(1)] 项目实战 实战2:命令行工具minigrep 有了昨天的基础,我们今天来开始另一个稍微有点 ...
- CSS3 zoom 属性
zoom:normal | <number> | <percentage> 默认值:normal normal: 使用对象的实际尺寸. <number>: 用浮点数 ...
- 神奇的系统bug
这是报错的日志 Status bar could not find cached time string image. Rendering in-process
- pycharm 如何自动添加头注释,比如时间,作者信息等
查找路径:File->settings->Editor->File and Code Templates->Python Script #!/usr/bin/env pytho ...
- axios时遇到的Request Method: OPTIONS
前言 在请求axios 请求数据的时候,会出现options的,是因为请求是分为简单请求和复杂请求. 简单请求 满足下面两个条件的请求是简单请求: 请求方式是以下三种之一: HEAD GET POST ...
- es6的Set结构
今天看了一下es6的文档,发现还是比较实用的,Set结构可以用来数组的去重哎 let arr = [1,3,6,3,1,9] let arr1 = new Set(arr) [...arr1]的值就是 ...
- Codeforces 852F String Compression
题目 OvO http://codeforces.com/contest/825/problem/F 题解 KMP+DP 十分优雅地利用了KMP的fail数组 fail[k]表示第k个后缀的的fail ...
- node简单起服务
1.建一个app.js文件 const http = require('http'); const chalk = require('chalk'); const conf = require('./ ...
- CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)G
题面 一道暴水的dp....别问我为什么直接打开了G题,我只是对题目名称感兴趣而已.... #include<bits/stdc++.h> #define ll long long usi ...
- docker 卸载与安装
卸载 Docker自17.03版本开始分为两个版本Docker CE和Docker EE: Docker CE:Docker Community Edition,即Docker社区版 Docker E ...