dysonance/Indicators.jl

Simple Moving Average with the end points

Opened this issue · 1 comments

Is it possible to include a keyword argument to calculate the sma with the end points?

So for an array $y_t$, let $\beta_t$ be the moving average defined as

$$\begin{align} \beta_{t = 1} &= \frac{1}{2}(y_1 + y_2) \\\ \beta_{1 < t < T} &= \frac{1}{3}(y_{t - 1} + y_t + y_{t + 1}) \\ \beta_{t = T} &= \frac{1}{2}(y_{T- 1} + y_{T}) \end{align}$$

@affans That doesn't sound particularly difficult from an implementation standpoint. Could you help me understand how you'd envision calling the function? Is it the correct interpretation of your example/notation that in this case the "lookaround" parameter n would be $n=3$? It sounds like you're interested in applying some kind of sliding window of size $n$ centered at time $t$ that would average the nearby points both before and after $y_t$. That is, roughly speaking:

$$ \beta_{t}(n) = \frac{1}{n} \cdot \sum_ {i=t-\frac{n}{2}} ^ {t+\frac{n}{2}} \left[ y_t \right] \qquad \forall t \in [n, T-n] $$

Is that the right interpretation of what you're after?