Documentation

movavg

Leading and lagging moving averages chart

Syntax

movavg(Asset, Lead, Lag, Alpha)
[Short, Long] = movavg(Asset, Lead, Lag, Alpha)

Arguments

Asset

Security data, a vector of time-series prices.

Lead

Number of samples to use in leading average calculation. A positive integer. Lead must be less than or equal to Lag.

Lag

Number of samples to use in the lagging average calculation. A positive integer.

Alpha

(Optional) Control parameter that determines the type of moving averages. 0 = simple moving average (default), 0.5 = square root weighted moving average, 1 = linear moving average, 2 = square weighted moving average, and so on. To calculate the exponential moving average, set Alpha ='e'.

    Note:   When Alpha ='e', the value of the moving average depends on all previous data points (due to the iterative calculation). In this case, the Lead and Lag parameters are used to calculate the weighting factor for their respective averages (which is different from the number of samples).

Description

movavg(Asset, Lead, Lag, Alpha) plots leading and lagging moving averages.

[Short, Long] = movavg(Asset, Lead, Lag, Alpha) returns the leading Short and lagging Long moving average data without plotting it.

Examples

expand all

Compute the Moving Average for DIS Closing Prices

Load the DIS closing prices using disney.mat.

load disney.mat

Use movavg to plot the leading and lagging moving averages for DIS.

movavg(dis_CLOSE,3,20,1);ylabel('Price')
legend('Asset Price','Lagging Long','Leading Short')

Was this topic helpful?