The Elite Circle - Lag Calculation for Octave (MatLab)

 Categories Show Search Help

 The Elite Circle File sharing for Elite Members only, includes any and all platforms and file types

Entries
Lag Calculation for Octave (MatLab)
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

 Details: Lag Calculation for Octave (MatLab) Category: The Elite Circle  June 30th, 2014 Size: 2.17 KB