Financial Time Series Toolbox    
tsmovavg

Moving average

Syntax

Arguments

tsobj
Financial time series object
lead
Number of following data points
lag
Number of previous data points
vector
Row vector or row-oriented matrix. Each row is a set of observations.
dim
(Optional) Specifies dimension when input is a vector or matrix. Default = 2 (row-oriented). If dim = 1, input is assumed to be a column vector or column-oriented matrix (each column being a set of observations). output is identical in format to input.
timeperiod
Length of time period
numperiod
Number of periods considered
weights
Weights for each element in the window
pivot
Point where the average should be placed

Description

output = tsmovavg(tsobj, 's', lead, lag) and
output = tsmovavg(vector, 's', lead, lag, dim)
compute the simple moving average. 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
output = tsmovavg(vector, 'e', timeperiod, dim)
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 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
output = tsmovavg(vector, 't', numperiod, dim)
compute the triangular moving average. The triangular moving average double-smooths the data. 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
output = tsmovavg(vector, 'w', weights, pivot, dim)
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 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
output = tsmovavg(vector, 'm', numperiod, dim)
calculate the modified moving average. The first moving average value is calculated by averaging the past 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

mean, peravg

Reference

Achelis, Steven B., Technical Analysis from A To Z, Second printing, McGraw-Hill, 1995, pp. 184-192.


  tsmom typprice