## Introduction

Exponentially Weighted Moving Average (EWMA or EWA) is a simple and powerful tool in quantitative trading. There are a lot of technical analysis articles about this concept. There are some articles explaining the situation under varying or irregular intervals. I write this note in order to apply it to intra-day trading.

## Regular Intervals

EWA is a smoothing technique for both prices and volatilities. Generally, let \(Y\) be EWA, for regular intervals,

\[ \begin{aligned} {Y}_n &= \alpha * X_n + (1-\alpha) *{Y}_{n-1} = Y_{n-1}+\alpha*(X_n-Y_{n-1}) \\ \alpha &= \frac{2}{1+days}=\frac{1}{(1+days)/2}=\frac{1}{G} \end{aligned} \]

The deonominator \(G\) is related to the concept of half-life as described here.

Specifically, consider any time scale, e.g., minutes or seconds instead of days,

\[ \begin{aligned} Y_n &= \alpha X_n+(1-\alpha) Y_{n-1} \\ &= \alpha X_n+\alpha(1-\alpha)X_{n-1}+(1-\alpha)^2Y_{n-2}=... \\ &=\alpha \left[ X_n + (1-\alpha) X_{n-1} + (1-\alpha)^2X_{n-2} + ... \right] \end{aligned} \]

Neglecting first coefficient, assume each step is \(\Delta t\), half life is \(H\) in unit of time or \(H/{\Delta t}\) in steps,

\[ \begin{aligned} (1-\alpha)^{H / \Delta t} &= 0.5 \rightarrow \alpha = 1-e^{ln0.5\frac{\Delta t}{H}} \\ &\approx -ln0.5\frac{\Delta t}{H} \end{aligned} \]

It is obvious to see that in daily case \[ G = \frac{H}{-ln0.5}=1.4427H \]

## Irregular Intervals

Now consider an **irregular tick arrival**. For example, \(G=10s\) and current EWA is \(100\).

**Case One**: next tick comes in \(1\) second with price \(101\), then new EWA is

\[ \begin{aligned} \alpha &= 1-e^{-1/10}=0.09516\\ Y_1 &= Y_0 + \alpha (X_1-Y_0) = 100.095 \end{aligned} \]

**Case Two**: If rather the next tick comes in \(400\)ms,

\[ \begin{aligned} \alpha &= 1-e^{-0.4/10}=0.0392\\ Y_1 &= Y_0 + \alpha (X_1-Y_0) = 100.039 \end{aligned} \]

Therefore current EMA \(100\) is more relevant in case two.

Furthermore, in **case two**, if after 600ms another tick comes in, then \[
\begin{aligned}
Y_2 &= \alpha_2 X_2 + (1-\alpha_2)Y_1 \\
&=\alpha_2 X_2 + (1-\alpha_2)\alpha_1 X_1 + (1-\alpha_2)(1-\alpha_1)Y_0
\end{aligned}
\]

where the weight of \(Y_0\) or current EWA at \(100\) is \((1-\alpha_2)(1-\alpha_1)=e^{-0.6/10}e^{-0.4/10}=e^{-1/10}\), which is exactly the weight on \(Y_0\) in **case one**. In other words, current EWA decays at the same rate regardless which path it takes, e.g., either 1sec or 400ms+600ms, or any other route.

In sum, for irregular arrivals, the EWA weight follows expnential distribution. This idea is implemented in the intraday moving average strategy.

**DISCLAIMER: This post is for the purpose of research and backtest only. The author doesn't promise any future profits and doesn't take responsibility for any trading losses.**