Quick question/explination Re 'movavg'

조회 수: 5 (최근 30일)
Scragmore
Scragmore 2011년 12월 22일
Hi,
I have just created five arrays, four of them using 'movavg' of variang sample lengths, the last array is just the raw data.
>> [mavS1, mavS2] = movavg(LSEtest{7,2}(:,5),5,20,'e');
>> [mavS3, mavS4] = movavg(LSEtest{7,2}(:,5),50,200,'e');
>> mavS0 = LSEtest{7,2}(:,5);
What is confusing me is that they are all the same size, "double 466x1". This should not be correct as my raw data is 466x1 and a movavg of '200' must be no more than 266x1 as there is insufficient data points for the first 200 entries to creat the average. I have looked at the m-files for movavg and filter and I am just not getting it. Could some one please explain so I know which data points I need to ignore/discard.
Regards,
AD
  댓글 수: 3
Scragmore
Scragmore 2011년 12월 22일
Yes, I noticed as well, and with some of my plots. I suspect that the 'n' points, where 'n' = sample length, are just an average to date/point but would just like a confirmation.
Thanks.
AD
Walter Roberson
Walter Roberson 2011년 12월 22일
Related material: http://www.mathworks.com/matlabcentral/answers/1190-movavg-function-lead-and-lag-meaning

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt Tearle
Matt Tearle 2011년 12월 22일
With filter, ignore the first n points. However, you're using the 'e' option, which doesn't actually call filter. It uses the code:
for j = 2:r
a(j) = a(j-1) + alphal*(asset(j) - a(j-1));
end
where alphal is determined by the lead n, and a(1) = asset(1). Hence, the output values are, in fact, legitimately determined for the entire length of the data set. Essentially, the window length goes from the beginning of the data to the current point.
  댓글 수: 2
Scragmore
Scragmore 2011년 12월 23일
Thanks for the explanation, although I haven't full worked the equation I understood what an 'e'MA was. You did however highlight the fact I was using an exponential MA and point me in the direction to ans my own Q? to my satisfaction.
Before for I ans my own question I just wanted to comment your ans. I am not sure I would say legitimately determined (mathematicians please correct if I am wrong), although the exponential MA puts greater weight on to the most resent values in the data set sample, all contributions are not zero. Therefore even if you are missing one data point from the sample size, although possibly negligible it still effects the results.
My ans. I ran the same 'movavg' but on a normal non weighted MA. I found the the arrays were again all the same size. What I think is happening is
ans = sum/sample_size_requested;
where the sum does not necessarily contain the number of data points required. So for most cases the value returned is not significant until sample size is met. In my asses 5, 20, 50, 200.
Thanks for your time.
Ad
Matt Tearle
Matt Tearle 2011년 12월 27일
Yeah, "legitimately" was the best word I could think of at the time. I guess what I really meant was "isn't zero padded". That's the big difference between 'e' and the others. You're right that they all return the same sized vectors as the input. With the regular averaging (using filter), the start of the output is essentially what you said: sum/n even though the sum doesn't include n elements (equivalently, the sum includes n values which are padded with zeros when there's fewer than n data points).
A good way to see the difference between 'e' and the others is to try it on some constant data:
n = 100;
x = linspace(0,1,n)';
y = ones(n,1);
[ysl,yst] = movavg(y,5,20,0);
plot(x,y,x,ysl,x,yst)
figure
[ysl,yst] = movavg(y,5,20,'e');
plot(x,y,x,ysl,x,yst)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by