>Your filter code below works just fine when compared to what I had been
>doing, except for a number of initial days, due to what values are assumed
>in negative time. I had been using the following code:
>
># "ndays" is the number of days to be used when computing the exponential
>moving average of "data" (data is a column vector)
> data = "" ndays, 1); data]; # repeat data(1) ndays times at
>the beginning of data for negative time values
> alpha = 2/(ndays+1);
> n = length(data);
> avg = zeros(n,1);
> avg(1) = data(1);
The above instruction is all you need to "invent" past memory for
negative values. You should do the same for the filter function, but I
could not say how to do it offhand.
> for i = 2 : n
> ao = avg(i-1);
> avg(i) = ao + alpha*(data(i) - ao);
> endfor
>
># trim off run-in period for negative time values
> long_ma = long_ma(lma_days+1 : end);
I don't understand the above instruction. What is long_ma?
>For small values of ndays, the number of initial days where there's a
>discrepancy with your filter() implementation is minimal, but for larger
>values of ndays, the number of initial days of discrepancy grows (obviously,
>due to the nature of an exponential MA having a long-tail memory). Note, I
>add similar negative time values to the front of the vector when using
>filter() as well. I'm just not sure what is the convention when it comes to
>calculating exponential moving averages for points in "data" where "ndays"
>reaches back into negative time. Thanks again.
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email:
address@hidden
(entrance 20, 1st floor, room C71) Web:
http://fly.isti.cnr.it/