2
$\begingroup$

I'm a newbie to Signal Processing - and so I'm providing a "background" and a "question" section separately.


Background:

Suppose I have a linear filter (w.r.t. given as

$\theta_{t+1} = \theta_t + \lambda (x_t - \theta_t)$

In Financial Trading, such a filter is often called an exponential moving average, often applied to both prices (to get smoothened prices) and to square of price returns (to get "EWMA" volatility). By conventional definition:

$\lambda = \frac{2}{n+1}$, where $n$ is periods (example $20$-day EWMA volatility).

Usually, a lot of folks in Financial Trading define "lag" as the expected value of the filter, when $x_u$ is replace by $t-u$. For instance, the above filter can also be written as

$\theta_{t+1} = \lambda (x_t+(1-\lambda) x_{t-1}+ (1-\lambda)^2 x_{t-2}+ ...)$

To get the "lag" of this filter in Financial Trading, we write

$L(\theta) = \lambda (0+(1-\lambda) 1+ (1-\lambda)^2 2+ ...)$

which gives

$L(\theta) = (1-\lambda)/\lambda = \frac{n-1}{2}$.


Question:

Now suppose I have a filter that is non-linear in $\theta$. Example, suppose it is

$\theta_{t+1} = \theta_t + \lambda \frac{1}{2}(x_{t}^2 e^{2\theta_t}-1)$

I have no idea what would be the equivalent of a lag here. Some folks told me that the definition of lag in Financial Trading is equivalent to the group delay (or may be phase delay) in Signal Processing.

(1) I looked up the definition of group delay and phase delay (e.g. on Wiki), but I couldn't exactly relate them to the definition of lag in Financial Trading. For the linear example:

$\theta_{t+1} = \theta_t + \lambda (x_t - \theta_t)$

what would be the group delay (or may be phase delay if that's more equivalent)?

(2) For the non-linear example:

$\theta_{t+1} = \theta_t + \lambda \frac{1}{2}(x_{t}^2 e^{2\theta_t}-1)$

what would be the group delay / phase delay or the equivalent of lag as applied to the linear filters in Financial Trading?

$\endgroup$
  • $\begingroup$ the Wiki article is a bit of a mess. some of that i am to blame. i should revisit it and maybe fix it up a bit. your "exponential moving average" filter is what we in DSP would call a "1-pole filter". $\frac{1}{\lambda}$ is the "time constant" and i think, to relate that to the correct half-life, you need a $\log(2)$ in there somewhere, so i don't think your expression is correct. the group delay of a 1-pole filter is the same as its time constant, IIRC. i dunno what the relationship is with the phase delay, but i can try to figger it out. $\endgroup$ – robert bristow-johnson Jul 16 '15 at 20:49
  • $\begingroup$ I removed the referance to "half-life" to remove confusion and replaced it as $n$ is a period (e.g. $20$-day EWMA volatility). The rest of the background/question should be fine $\endgroup$ – uday Jul 16 '15 at 20:55
  • $\begingroup$ well, a one pole filter is pretty simple and well-defined. but the mathematical semantics that you financial guys like using leaves some to be desired. i'll get back to this tonight if no one else answers. also, i need to correct myself. the one-pole filter is not a linear-phase filter, so its group delay and phase delay are not constant. but, if the impulse response is $A \cdot e^{-\lambda t}$ (which i think it is), then the time-constant $\frac{1}{\lambda}$ is the same as both the group delay and the phase delay at a frequency of 0 (at DC). $\endgroup$ – robert bristow-johnson Jul 16 '15 at 21:02
2
$\begingroup$

i'm gonna work on this using the EE DSP notation i think is most conventional in the EE DSP field. your exponentially-decaying 1-pole filter has this simple difference equation:

$$ y[n] = (1-p) \, x[n] \ + \ p \, y[n-1] $$

turns out (as we shall see below) that $p$ is the pole. applying the Z transform gets you

$$ Y(z) = (1-p) \, X(z) \ + \ p \, z^{-1}Y(z) $$

from which we can solve for the transfer function:

$$ H(z) \triangleq \frac{Y(z)}{X(z)} = \frac{1-p}{1-p\,z^{-1}} = (1-p)\frac{z}{z-p} $$

so there is a zero at $z=0$ and a (real) pole at $z=p$. the zero would go away if we took our input from $x[n-1]$ instead of $x[n]$ which would create a pole at $z=0$ and cancel the zero, but all that does is introduce another sample period of delay. i don't think you wanna do that.

the (Kronecker) impulse response is

$$ \begin{align} h[n] & = (1-p) p^n u[n] \\ & = (1-p) e^{\log(p) \, n} u[n] \\ & = (1-p) e^{n / \tau} u[n] \\ \end{align} $$

where u[n] is the Heaviside unit step function

$$ u[n] \triangleq \begin{cases} 1, & \text{if }n \ge 0 \\ 0, & \text{if }n < 0 \end{cases} $$

and $\tau$ is the "time constant" of the decaying exponential. in order for the filter to be stable, the exponential must be decaying which means that $\tau > 0$, $\log(p) < 0$, and $0 < p < 1$

okay, so now the complex frequency response of $H(z)$ is

$$ \begin{align} H(z)\bigg|_{z=e^{j\omega}} = H(e^{j\omega}) & = \frac{1-p}{1-p \, e^{-j\omega}} \\ & = \frac{1-p}{1-p \, \left(\cos(\omega) + j\sin(\omega) \right)} \\ \end{align} $$

the magnitude response is

$$ \begin{align} |H(e^{j\omega})| & = \left|\frac{1-p}{1-p \, e^{-j\omega}} \right| \\ & = \left| \frac{1-p}{1-p \, \left(\cos(\omega) + j\sin(\omega) \right)} \right| \\ & = \frac{1-p}{\sqrt{ (1-p\cos(\omega))^2 + (p\sin(\omega))^2 }} \\ & = \frac{1-p}{\sqrt{ 1 + p^2 - 2 p \cos(\omega) }} \\ \end{align} $$

this is pretty familiar. less oft observed is the phase response

$$ \begin{align} \phi(\omega) \triangleq \arg \{ H(e^{j\omega}) \} & = \arg \left\{ \frac{1-p}{1-p \, e^{-j\omega}} \right\} \\ & = \arg \{ 1-p \} - \arg \{1-p \, e^{-j\omega} \} \\ & = 0 - \arg \{1-p (\cos(\omega) + j \sin(\omega)) \} \\ & = - \arctan \left( \frac{p \sin(\omega)}{1-p \cos(\omega)} \right) \\ \end{align} $$

the phase delay is

$$ \tau_\phi(\omega) \triangleq -\frac{\phi(\omega)}{\omega} $$

and the group delay is

$$ \tau_g(\omega) \triangleq -\frac{d\phi(\omega)}{d\omega} $$

gotta go. i'll post this now and finish it later. perhaps someone else wants to finish it.

$\endgroup$
  • $\begingroup$ Thanks. I think I found my answer. Lag as defined by Financial Traders would be equal to $-\frac{dH(z)}{dz}\bigg|_{z=1}$ whose solution matches with a few filters that I tried. $\endgroup$ – uday Jul 17 '15 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.