# movingaveExpwgt¶

## Purpose¶

Computes exponentially weighted moving average of a series.

## Format¶

y = movingaveExpwgt(x, d, p)
Parameters:
• x (NxK matrix) – data

• d (scalar) – order of moving average.

• p (scalar) – smoothing coefficient where $$0 > p > 1$$.

Returns:

y (NxK matrix) – filtered series. The first $$d-1$$ rows of x are set to missing values.

## Examples¶

### Smoothing of random walk data¶

// Create random data, setting initial seed
// value to be the hundredths of a second
// since midnight
numPoints = 1000;
seed = hsec;
{ delta, state } = rndn(numPoints, 1, seed);

// Set mean of data to be > 0
// to give data long term positive bias
delta = delta + 0.01;

// Increase magnitude of delta to
// create desired level of volatiliy
delta = 2*delta;

// Instantiate y : index price data
y = 1000*ones(numPoints,1);

// Loop through y and add the cumulative
// sums of delta to create random walk
for i(2, numPoints, 1);
y[i]= y[i-1] + delta[i];
endfor;

// Find moving average
twentyMA = movingaveExpwgt(y, 20, 0.8);


## Remarks¶

movingaveExpwgt() is smoothing time series filter using exponential weights. The moving average as performed by column and thus it treats the NxK matrix as K time series of length N.