Skip to content
Prev 278613 / 398502 Next

generating a vector of y_t = \sum_{i = 1}^t (alpha^i * x_{t - i + 1})

On Nov 27, 2011, at 9:25 AM, R. Michael Weylandt wrote:

            
It's pretty close for EMA(1:1000, n=1,  ratio=0.5) and 7 times faster.

 > EMA(1:10, n=1,  ratio=0.5)
  [1] 1.000000 1.500000 2.250000 3.125000 4.062500 5.031250 6.015625  
7.007812 8.003906
[10] 9.001953
 > loopRec3(1:10, 0.5)
  [1] 0.500000 1.250000 2.125000 3.062500 4.031250 5.015625 6.007812  
7.003906 8.001953
[10] 9.000977

This series converges very quickly to n-1 when the ratio = 0.5 and to  
n-3 when ratio = 0.25. It's already within 1% at the fifth iteration.  
There may be a simple analytical approximation that makes the process  
even more efficient. The asymptotic result appears to be:  n-(1-ratio)/ 
ratio

 > tail(EMA(1:1000, n=1,  ratio=0.5))
[1] 994 995 996 997 998 999
 > tail(loopRec3(1:1000, 0.5))
[1] 994 995 996 997 998 999

 > EMA(1:1000, n=1,  ratio=0.1)[491:500]
  [1] 482 483 484 485 486 487 488 489 490 491