Financial Time Series Toolbox | ![]() ![]() |
Syntax
output = tsmovavg(tsobj, 's', lead, lag) (Simple) output = tsmovavg(vector, 's', lead, lag, dim) output = tsmovavg(tsobj, 'e', timeperiod) (Exponential) output = tsmovavg(vector, 'e', timeperiod, dim) output = tsmovavg(tsobj, 't', numperiod) (Triangular) output = tsmovavg(vector, 't', numperiod, dim) output = tsmovavg(tsobj, 'w', weights, pivot) (Weighted) output = tsmovavg(vector, 'w', weights, pivot, dim) output = tsmovavg(tsobj, 'm', numperiod) (Modified) output = tsmovavg(vector, 'm', numperiod, dim)
Arguments
Description
output = tsmovavg(tsobj, 's', lead, lag) and
compute the simple moving average.
output = tsmovavg(vector, 's', lead, lag, dim)
lead
and lag
indicate the number of previous and following data points used in conjunction with the current data point when calculating the moving average. For example, if you want to calculate a five-day moving average, with the current data in the middle, you set both lead
and lag
to 2
(2 + 1 + 2 = 5).
output = tsmovavg(tsobj, 'e', timeperiod) and
compute the exponential weighted moving average. The exponential moving average is a weighted moving average with the assigned weights decreasing exponentially as you go further into the past. If
output = tsmovavg(vector, 'e', timeperiod, dim)
is a smoothing constant, the most recent value of the time series is weighted by
, the next most recent value is weighted by
(1-
), the next value by
(1-
)2, and so forth. Here,
is calculated using 2/(
timeperiod
+1), or 2/(Windows_size+1).
output = tsmovavg(tsobj, 't', numperiod) and
compute the triangular moving average. The triangular moving average double-smooths the data.
output = tsmovavg(vector, 't', numperiod, dim)
tsmovavg
calculates the first simple moving average with window width of numperiod/2
. If numperiod
is an odd number, it rounds up (numperiod/2
) and uses it to calculate both the first and the second moving average. The second moving average a simple moving average of the first moving average. If numperiod
is an even number, tsmovavg
calculates the first moving average using width (numperiod/2
) and the second moving average using width (numperiod/2)+1
.
output = tsmovavg(tsobj, 'w', weights, pivot) and
calculate the weighted moving average by supplying weights for each element in the moving window. The length of the weight vector determines the size of the window. For example, if
output = tsmovavg(vector, 'w', weights, pivot, dim)
weights = [1 1 1 1 1]
and pivot = 3
, tsmovavg
calculates a simple moving average by averaging the current value with the two previous and two following values.
output = tsmovavg(tsobj, 'm', numperiod) and
calculate the modified moving average. The first moving average value is calculated by averaging the past
output = tsmovavg(vector, 'm', numperiod, dim)
numperiod
inputs. The rest of the moving average values is calculated by adding to the previous moving average value the current data point divided by numperiod
and subtracting the previous moving average divided by numperiod
. Moving average values prior to the numperiod
value are copies of the data values.
See Also
Reference
Achelis, Steven B., Technical Analysis from A To Z, Second printing, McGraw-Hill, 1995, pp. 184-192.
![]() | tsmom | typprice | ![]() |