mTopRange
Syntax
mTopRange(X, window, [minPeriods])
Please see mFunctions for the parameters and windowing logic.
Details
For each element Xi in a sliding window of X, count the continuous nearest neighbors to its left that are smaller than Xi. NULLs are treated as the minimum values.
If X is a matrix, conduct the aforementioned calculation within each column of X.
Examples
x = [NULL, 3.1, NULL, 3.0, 2.9, 2.8, 3.1, NULL, 3.2]
mTopRange(x, window=3)
// output: [,,0,1,0,0,2,0,2]
mTopRange(x, window=3, minPeriods=1)
// output: [,1,0,1,0,0,2,0,2]
x = [NULL, NULL, NULL, NULL, NULL, 2, NULL, NULL, 3.2]
date = [0, 1, 2, 3, 7, 8, 9, 10, 11] + 2020.01.01
X = indexedSeries(date, x) 
mTopRange(X, 3d)
            | 
                                 #0  | 
                        |
|---|---|
| 2020.01.01 | |
| 2020.01.02 | |
| 2020.01.03 | |
| 2020.01.04 | |
| 2020.01.08 | |
| 2020.01.09 | 1 | 
| 2020.01.10 | 0 | 
| 2020.01.11 | 0 | 
| 2020.01.12 | 2 | 
m = matrix(1 2 3 NULL, 1 2 NULL 3, 1 3 NULL NULL, 1 2 3 4)
mTopRange(m, 2)
            | 
                                 #0  | 
                            
                                 #1  | 
                            
                                 #2  | 
                            
                                 #3  | 
                        
|---|---|---|---|
| 
                                 
  | 
                            |||
| 1 | 1 | 1 | 1 | 
| 1 | 0 | 0 | 1 | 
| 0 | 1 | 1 | 
