createLags function - Hows does it compute ?
    3 views (last 30 days)
  
       Show older comments
    
    Jan Morawietz
 on 25 Nov 2014
  
    
    
    
    
    Answered: Jan Morawietz
 on 25 Nov 2014
            I'm currently trying to understand a matlab code of trend following. At some point, the code uses Matlab's "createLages" function. Can someone please explain me how this function works?
If I follow the official Matlab example, the function gives me:
x = [1 2 3 4; -1 -2 -3 -4]';
y = createLags(x, [-1 0 2]);
y =
       2    -2     1    -1   NaN   NaN
       3    -3     2    -2   NaN   NaN
       4    -4     3    -3     1    -1
     NaN   NaN     4    -4     2    -2
For explanation, "Matlab-file-help" example says:
"predictorMatrix (outcome) is a numObs-by-numDim*numLags matrix of the shifted versions of the input matrix"
However, if I follow this approach I'd get something like
t = [(x-1) (x-0) (x+2)]
   0    -2     1    -1     3     1
       1    -3     2    -2     4     0
       2    -4     3    -3     5    -1
       3    -5     4    -4     6    -2
... which of course I can't multiply with x anymore..
Any advice greatly appreciated!
Best
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
				Find more on Logical in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!