Introduction
In statistics, a moving average (rolling average or running average) is a calculation to analyze data points by creating series of averages of different subsets of the full data set. It is also called a moving mean (MM) or rolling mean and is a type of finite impulse response filter. Variations include: simple, and cumulative, or weighted forms (described below).
Given a series of numbers and a fixed subset size, the first element of the moving average is obtained by taking the average of the initial fixed subset of the number series. Then the subset is modified by "shifting forward"; that is, excluding the first number of the series and including the next number following the original subset in the series. This creates a new subset of numbers, which is averaged. This process is repeated over the entire data series. The plot line connecting all the (fixed) averages is the moving average. A moving average is a set of numbers, each of which is the average of the corresponding subset of a larger set of datum points. A moving average may also use unequal weights for each datum value in the subset to emphasize particular values in the subset.
已知一组序列和一个确定的子集大小,移动平均的第一个元素来自该序列的初始子集。而后子集继续向前移动,也就是,剔除序列的第一个成员再加入原序列的后一个成员。这就刚刚创建一个新的子集,求平均值。此过程在全序列不断重复至结束。图上与全部平均值关联的线段就是移动平均线。一个移动平均就是一个数值集合,每一元素对应较长数值序列的相应子集的平均值。移动平均可能采用加权计算,来突出特定样点在子集中的重要程度。
A moving average is commonly used with time series data to smooth out short-term fluctuations and highlight longer-term trends or cycles. The threshold between short-term and long-term depends on the application, and the parameters of the moving average will be set accordingly. For example, it is often used in technical analysis of financial data, like stock prices, returns or trading volumes. It is also used in economics to examine gross domestic product, employment or other macroeconomic time series. Mathematically, a moving average is a type of convolution and so it can be viewed as an example of a low-pass filter used in signal processing. When used with non-time series data, a moving average filters higher frequency components without any specific connection to time, although typically some kind of ordering is implied. Viewed simplistically it can be regarded as smoothing the data.
移动平均常应用在时间序列数据,平滑短期的波动并强调长期的趋势(周期)。短期和长期之间的阈值取决于实际情况,此时的移动平均参数须有对应的配置。例如,它常用在金融数据的技术分析,股价……数学上,一个移动平均就是一种卷积类型,所以他可以被视为信号处理的低通滤波器。当应用在非时间序列上,移动平均滤波不附带时间属性的高频率组分,即是该序列顺序有一定潜在意义。简单讲,移动平均是光滑数据的一种方式。
In financial applications a simple moving average (SMA) is the unweighted mean of the previous n data. However, in science and engineering the mean is normally taken from an equal number of data on either side of a central value. This ensures that variations in the mean are aligned with the variations in the data rather than being shifted in time. An example of a simple equally weighted running mean for a n-day sample of closing price is the mean of the previous n days' closing prices. If those prices are pM, pM-1, ..., pM-(n-1) then the formula is
\[SMA = \frac{{{p_M} + {p_{M - 1}} + \cdots + {p_{M - \left( {n - 1} \right)}}}}{n}\]
还有Cumulative moving average,Weighted moving average,Exponential moving average,
时间尺度n确定方法
时间尺度n在不同的应用领域数值应是不同的,可以通过一定的算法估算具体情况下n的大小。移动平均(如简单移动平均等)并不一定有便捷的途径计算n的取值,但中心移动平均可以快速的求算n。所以,不妨利用中心移动平均求算n的途径为其他移动平均(如简单移动平均等)计算n的取值。
第一步,设置多种时间尺度(n=2,3……),原时间序列应用中心移动平均(Centered Moving Average)求得新的时间序列。
第二步,计算不同时间尺度下原时间序列与新输出时间序列的绝对差值代数和(Sum of absolute differences)。
第三步,图形展示不同时间尺度的代数和。曲线上的拐点(Knee Point of the Curve)即是对应于原时间序列的最佳时间尺度n。拐点的二阶导数等于0。
Fig. 1
如Fig. 1所示,(a)是原时间序列,(b)指出n等于9时是绝对差值代数和曲线的拐点,(c)黑线是原时间序列设定n为9时的中心移动平均曲线。
References