主要内容

movavg

财务时间序列的移动平均值

movavg已更新以接受数据输入作为矩阵,桌子, or时间表.

The syntax formovavghas changed. There is no longer support for the input arguments带领落后, only a singlewindowSize受支持万博1manbetx,只有一个输出参数()。如果要计算领先和滞后的移动平均值,则需要运行movavgtwice and adjust thewindowSize.

Description

example

= movavg(数据,type,windowSize)计算财务时间序列的移动平均值(MA)。

example

= movavg(___,Initialpoints)adds an optional argument forInitialpoints.

example

= movavg(数据,type,权重)computes the moving average (MA) of a financial time series using a'custom'type权重.

example

= movavg(___,Initialpoints)adds an optional argument forInitialpoints.

Examples

collapse all

Load the fileSimulatedStock.mat, which provides a timetable (TMW)用于财务数据。

loadSimulatedStock.mattype ='linear'; windowSize = 14; ma = movavg(TMW_CLOSE,type,windowSize)
嘛=1000×1100.2500 100.3433 100.8700 100.4916 99.9937 99.3603 98.8769 98.6364 98.4348 97.8491 ⋮

Load the fileSimulatedStock.mat, which provides a timetable (TMW)用于财务数据。

loadSimulatedStock.mattype ='linear'; malag=movavg(TMW_CLOSE,type,20)%滞后移动平均值
malag =1000×1100.2500 100.3423 100.8574 100.4943 100.0198 99.4230 98.9728 98.7509 98.5688 98.0554 ⋮
嘛lead=movavg(TMW_CLOSE,type,3)领先移动平均线
嘛lead =1000×1100.2500 100.3580 101.0900 100.4300 99.3183 97.8217 97.0833 97.1950 97.4133 96.1133 ⋮

Plot the leading and lagging moving averages.

plot(TMW_CLOSE(1:100)) holdplot(malead(1:100)) plot(malag(1:100)) hold离开legend('实际的','Lead','落后')

Figure contains an axes. The axes contains 3 objects of type line. These objects represent Actual, Lead, Lag.

Input Arguments

collapse all

财务系列的数据,指定为面向列的矩阵,表格或时间表。时间表和表必须包含一个数字类型的变量。

数据Types:double|桌子|时间表

移动平均值的类型计算,指定为具有关联值的字符向量或字符串。

数据Types:char|string

输入序列的观察数包括在移动平均值中,指定为标量正整数。观察结果包括(windowSize- 1) previous data points and the current data point.

Note

ThewindowSizeargument applies only to moving averages whosetypeis'simple','平方根','linear','square','exponential','triangular', or'修改的'.

数据Types:double

Custom weights used to compute the moving average, specified as a vector.

Note

The length of weights (N)确定移动平均窗口的大小(windowSize)。The权重argument applies only to a'custom'typeof moving average.

为了计算自定义权重的移动平均值(权重)(w) are first normalized such that they sum to one:

W(i) = w(i)/sum(w), for i = 1,2,...,N

The normalized weights (W) are then used to form theN-point weighted moving average (y)输入数据(x):

y(t) = W(1)*x(t) + W(2)*x(t-1) + ... + W(N)*x(t-N)

最初的移动平均线lues within the window size are then adjusted according to the method specified in the name-value pair argumentInitialpoints.

数据Types:double

(Optional) Indicates how the moving average is calculated at initial points (before there is enough data to fill the window), specified as a character vector or string using one of the following values:

  • '收缩'- Initializes the moving average such that the initial points include only observed data

  • '零'- Initializes the initial points with0

  • '填'- Fills initial points withNaNs

Note

TheInitialpoints参数适用于所有typespecifications except for the'exponential''修改的'options.

数据Types:char|string

Output Arguments

collapse all

Moving average series, returned with the same number of rows (M) and the same type (matrix, table, or timetable) as the input数据.

参考

[1] Achelis, S. B.Technical Analysis from A to Z.Second Edition. McGraw-Hill, 1995, pp. 184–192.

在R2006a之前引入