Re: [R] Need help to optimize a piece of code involving zoo objects

2009-06-22 Thread Sergey Goriatchev
Hi, everybody OK, I got it working with "recursive". Don't know why this argument slipped my mind, as I use filter() so often! Now it is 44 times faster, which is good enough for me. :-) Thank you, Gabor and Jim. Best, Sergey On Fri, Jun 19, 2009 at 15:23, jim holtman wrote: > check out 'filter

Re: [R] Need help to optimize a piece of code involving zoo objects

2009-06-19 Thread Sergey Goriatchev
Dear Gabor and Jim I am not looking at the "recursive" method for filter() Recursive filter with lag 1 is specified in help files as: y[i] = x[i] + f[1]*y[i-1] My function looks like this: EMA[i] = K*(C[i] - EMA[i-1]) + EMA[i-1], that is: y[i]=EMA[i] y[i-1]=EMA[i-1] x[i]=C[i] So, I modified my

Re: [R] Need help to optimize a piece of code involving zoo objects

2009-06-19 Thread jim holtman
check out 'filter' to see if it does what you want with the 'recursive' option. On Fri, Jun 19, 2009 at 3:33 AM, Sergey Goriatchev wrote: > Hello, everyone > > I have a long script that uses zoo objects. In this script I used > simple moving averages and these I can very efficiently calculate wit

[R] Need help to optimize a piece of code involving zoo objects

2009-06-19 Thread Sergey Goriatchev
Hello, everyone I have a long script that uses zoo objects. In this script I used simple moving averages and these I can very efficiently calculate with filter() functions. Now, I have to use special "exponential" moving averages, and the only way I could write the code was with a for-loop, which