This script is inspired by John Ehlers works on using DSP for trading. His books and articles contain formulas that estimate lag for some indicators. However, how to estimate lag in general case?
This script uses the DFT Phase Response (PhR) to make this estimation. The negative shift in the PhR pushes the values to the right, thus delaying the signal. The raw PhR returns the angle value. However, we want to estimate lag in terms of bars (time delay). To do it, we need to take an account the frequency (or period) of the phase:
Lag = | min(Phase * Period) | = | min(Phase / Frequency) |
Then we need to take the minimal value and take its absolute value. We skip all frequencies above 0.5 (the maximum possible without aliasing).
Version: 0.1.1
Examples:
SMA(3):
>> a = [1];
>> b = [1/3,1/3,1/3];
>> lag(b,a)
ans = 1.0000
EMA(0.1):
>> a = [1,-0.9];
>> b = [0.1];
>> lag(b,a)
ans = 9.0000
Category The Elite Circle
|
|
|