| Financial Toolbox™ | ![]() |
movavg(Asset, Lead, Lag, Alpha) [Short, Long] = movavg(Asset, Lead, Lag, Alpha)
Asset | Security data, usually 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'. |
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.
Notes
|
If asset A is a vector of stock price data from 01/01/2006 to 02/01/2006
>> A(:,2)
ans =
8.6500
9.0000
8.8500
9.3500
9.5000
9.3500
9.2500
9.7000
9.9500
10.5000
10.1000
9.9000
10.0000
9.9000
9.6000
9.7000
9.8000
9.7000
9.9500
10.1500
9.8500
9.9000
10.2000
10.0000
9.9500
9.8500
9.9500
10.0000
10.0000
10.5400
10.5900
11.1900
11.0400
11.0900
10.7400
10.3500
10.2500
10.4500
10.7400
10.5900
10.3000
10.0500
9.8500
9.9000
9.9000
10.3000
10.4500
10.7400
10.9400
10.6900
10.9400
10.7900
10.2000
11.4900
11.9400
11.9400
12.4800
13.1800
12.9800
12.9800
13.6800
13.4800
13.9300
14.9200
13.9300
14.4200
14.0300
14.9700
15.0700
15.0200
15.0700
14.4200
13.7800
14.2800
14.8700
15.5700
15.5200
15.5200
15.5200
15.5200
15.7200
15.8200
15.9700
15.2700
14.9500
14.8000
15.1500
14.5000
15.0500
14.5500
14.6000
14.5500
17.5500
16.7000
16.8000
17.9500
17.3000
17.6000
17.5500
16.5000
15.8500
16.3000
then the moving average is
[Short,Long]= movavg(A(:,2),3,20,1);
movavg(A(:,2),3,20,1);
ylabel('Price')
legend('Asset Price','Lagging Long','Leading Short')this plots linear three-sample leading and 20-sample lagging moving averages

bolling, candle, dateaxis, highlow, pointfig
![]() | months | mrdivide | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |