I don’t understand how the TTR SMA function is handling weights. First, what is the difference between wts and w? Then, there is a result I do not expect.
I want to use a set of linear weights at each position of the SMA calculation so that the current value being calculated has the highest weight applied and the nth most distant value has the lowest weight. Here is an example that should give back the weights, if they worked the way I assumed (my example provides the impulse function of a linear filter):
t <- replicate(0, n = 12)
t[5] <- 1
weights <- c(0.25, 0.5, 0.75, 1.0)
SMA(t, n = 4, wts = weights)
But this gives: NA NA NA 0.00 0.25 0.25 0.25 0.25 0.00 0.00 0.00 0.00
This is the same result one gets if you use a set of weights of c(1,1,1,1). I would expect to see items 5-8 as 1.0, 0.75, 0.5, 0.25. I am unable to find any explanation in the Internet about how SMA is calculating the weighted SMA function.