Weight vector of an exponential moving average? With weight vector I mean the vector with weights that you have to multiply the observations in the window that slides over your data with so if you add those products together it returns the value of the EMA on the right side of the window.

For a linear weighted moving average the formula for finding the weight vector is: (1:n)/sum(1:n) (in R code). This series of length n adds up to 1. For n=10 it will be


  0.01818182
  0.03636364
  0.05454545
  0.07272727
  0.09090909
  0.10909091
  0.12727273
  0.14545455
  0.16363636
  0.18181818


the numbers 1 to 10 / 55, with 55 the sum of the numbers 1 to 10.

How do you calculate the weight vector for an exponential moving average (EMA) of length n?

Wikipedia  tells me:


  if n is the length of the window, then alpha&lt;-2/(n+1) and i&lt;-1:n so EmaWeightVector&lt;-((alpha*(1-alpha)^(1-i)))


Is this correct? 

Even though the EMA is not really confined to a window with a start and an end, shouldn't the weights add up to 1 just like with the LWMA?
ok the solution was: (in R)

emaweights&lt;-function(m)
{
  alpha&lt;-2/(m+1)
  i&lt;-1:m
  sm&lt;-sum((alpha*(1-alpha)^(1-i)))
  return(((alpha*(1-alpha)^(1-i)))/sm)  
}


Here the weights do add up to 1.