rowFilterAndSort
Syntax
rowFilterAndSort(sortVec, filterVec, orderedFilters, args...)
Details
Filters and sorts elements in array vectors or columnar tuples.
Elements of sortVec , filterVec and args... correspond to each other by position. This function first filters filterVec , then sorts sortVec and filterVec . The filtering and sorting criteria are specified by orderedFilters :
-
Filtering : Filters filterVec according to orderedFilters , retaining only the values specified in orderedFilters
-
Sorting : After filtering, sorts equal values in sortVec according to the order specified by orderedFilters based on the corresponding values in filterVec.
Parameters
sortVec is a numeric/temporal array vector or columnar tuple representing the sort-key column. sortVec can also be a tuple containing up to 3 array vectors or columnar tuples. The elements in each row must be ordered.
filterVec is a STRING columnar tuple representing the filter-key column to be filtered by orderedFilters and used for reordering. filterVec can also be a tuple containing up to 3 STRING columnar tuples.
orderedFilters is a STRING vector or tuple representing the priority order for filtering and reordering. If filterVec is a tuple, orderedFilters must also be a tuple with the same number of elements as filterVec .
args... (optional) can be array vectors or columnar tuples representing additional columns to be filtered and reordered together with sortVec using the same sorting order. The data form of args must be consistent with sortVec.
Returns
Returns a tuple. The tuple elements are: the expanded columns of the filtered and reordered results of sortVec , filterVec and args .
“Expanded” means that when sortVec, filterVec and args are tuples, each element of the filtered and reordered results independently becomes an element of the returned result tuple. For example, both sortVec, filterVec are tuples containing two elements, args contains three elements, and the returned result is a tuple containing 7 (=2+2+3) elements.
Examples
Example 1. Filter and sort the columnar tuples: The askPrices come from different sources (srcs). Now filter out prices from SRC3 or SRC1.For identical prices, order them with SRC3 first, followed by SRC1. The corresponding askVols are also filtered and sorted accordingly.
orderedFilters = `SRC3`SRC1
srcs = [`SRC1`SRC2`SRC3`SRC1`SRC3, `SRC1`SRC3`SRC1`SRC2`SRC3`SRC1`SRC2].setColumnarTuple!(true)
askPrices = [900 900 900 901 901, 800 800 802 802 802 803 803].setColumnarTuple!(true)
askVols = [10 15 20 15 20, 20 15 30 40 20 15 30].setColumnarTuple!(true)
rowFilterAndSort(askPrices, srcs, orderedFilters, askVols)
/*
output:
(([900,900,901,901],[800,800,802,802,803]),
(["SRC3","SRC1","SRC3","SRC1"],["SRC3","SRC1","SRC3","SRC1","SRC1"]),
([20,10,20,15],[15,20,20,30,15]))
*/
Example 2. For a tuple of array vectors: The askPrices correspond to different times and come from different sources (srcs), each with different clearing speeds. Now filter for the quotes coming from SRC1 or SRC3, with clearing speeds of T0, T1, or T2. The results will be sorted by price priority, time priority, with sources ordered as SRC1, SRC3, and clearing speeds ordered as T0, T1, T2. The corresponding order volumes askVols will also be filtered and sorted accordingly.
orderedFilters = [`SRC1`SRC3, `T0`T1`T2]
srcs = [`SRC1`SRC1`SRC3`SRC3`SRC3, `SRC3`SRC3`SRC1`SRC2`SRC3`SRC1`SRC2].setColumnarTuple!(true)
speeds = [`T1`T2`T0`T2`T4, `T2`T0`T1`T0`T0`T0`T1].setColumnarTuple!(true)
askPrices = array(INT[], 0, 10).append!([900 900 900 901 901, 800 800 802 802 802 803 803])
quoteTimes = array(SECOND[], 0, 10).append!([09:30:00 09:30:00 09:30:00 09:30:01 09:30:02,
09:30:00 09:30:00 09:30:00 09:30:00 09:30:00 09:30:00 09:30:00])
askVols = array(INT[], 0, 10).append!([10 15 20 15 20, 20 15 30 40 20 15 30])
rowFilterAndSort([askPrices,quoteTimes], [srcs,speeds], orderedFilters, askVols)
/*
output:
([[900,900,900,901],[800,800,802,802,803]],
[[09:30:00,09:30:00,09:30:00,09:30:01],[09:30:00,09:30:00,09:30:00,09:30:00,09:30:00]],
(["SRC1","SRC1","SRC3","SRC3"],["SRC3","SRC3","SRC1","SRC2","SRC3"]),
(["T1","T2","T0","T2"],["T0","T2","T1","T0","T0"]),
[[10,15,20,15],[15,20,30,20,15]])
*/
Related Functions: rowMergeAndSort
