NexusFi: Find Your Edge


Home Menu

 



Categories Help    

 
Lag Calculation for Octave (MatLab) 1 *
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 
 
Suggest other entries I might like
Details: Lag Calculation for Octave (MatLab)
Category: The Elite Circle 


June 30th, 2014
Size: 2.17 KB
Comments/ratings
1 * Zondor July 9th, 2014 07:54 PM
This is not an indicator download. Just wondering why it is here. Just asking....

 
Sort by

 




© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top