rowAlign

Syntax

rowAlign(left, right, how)

Arguments

left/right is an array vector.

Note:

  • left and right must be of the same data type and size (number of rows), but the number of elements in corresponding rows do not have to match. For example, if left has 3 rows and the first row has 5 elements, then right must also have 3 rows but the first row does not necessarily have 5 elements.

  • Data in each row of left and right must be strictly increasing/decreasing.

how is a string indicating how left and right will be aligned. The range of the alignment result is determined by how. It can take the following values:

how (case-insensitive) Description Max. Value in the Alignment Result Min. Value in the Alignment Result
"bid" left and right are bid prices sorted in strictly decreasing order. max(max(left), max(right)) max(min(left), min(right))
"ask" left and right are ask prices sorted in strictly increasing order. min(max(left), max(right)) min(min(left), min(right))
"allBid" left and right are bid prices sorted in strictly decreasing order. max(max(left), max(right)) min(min(left), min(right))
"allAsk" left and right are ask prices sorted in strictly increasing order. max(max(left), max(right)) min(min(left), min(right))

Details

The rowAlign function aligns the rows of left and right based on element values. It returns a tuple of two arrays vectors, indicating the indices of the aligned elements in the original left and right arrays respectively. Empty elements in the aligned rows are filled with -1 in the output arrays.

With the returned row index, you can call rowAt to extract the aligned elements from the original left and right arrays, with any unaligned elements left blank.

The images below illustrate how alignment is processed in each row:

  • how = “bid” or “allBid”

  • how = “ask” or “allAsk”:

例子

$ left = array(DOUBLE[], 0, 5).append!([9.01 9.00 8.99 8.98 8.97, 9.00 8.98 8.97 8.96 8.95, 8.99 8.97 8.95 8.93 8.91])
$ right = array(DOUBLE[], 0, 5).append!([9.02 9.01 9.00 8.99 8.98, 9.01 9.00 8.99 8.98 8.97, 9.00 8.98 8.97 8.96 8.95])
$ leftIndex, rightIndex = rowAlign(left, right, "bid")
$ leftIndex
[[-1,0,1,2,3],[-1,0,-1,1,2],[-1,0,-1,1,-1,2]]
$ left.rowAt(leftIndex)
[[,9.01,9.00,8.99,8.98],[,9,,8.99,8.97],[,8.99,,8.97,,8.95]]

$ rightIndex
[[0,1,2,3,4],[0,1,2,3,4],[0,-1,1,2,3,4]]
$ right.rowAt(rightIndex)
[[9.02,9.01,9.00,8.99,8.98],[9.01,9.00,8.99,8.98,8.97],[9.00,,8.98,8.97,8.96,8.95]]

// output all bid prices in one array vector after aligning left and right
$ left.rowAt(leftIndex).nullFill(right.rowAt(rightIndex))
[[9.02,9.01,9,8.99,8.98],[9.01,9.00,8.99,8.98,8.97],[9.00,8.99,8.98,8.97,8.96,8.95]]

// the bid sizes
$ leftBidQty = array(INT[], 0, 5).append!([10 5 15 20 13, 12 15 20 21 18, 7 8 9 9 10])
$ rightBidQty = array(INT[], 0, 5).append!([8 12 10 12 8, 10 5 15 18 13, 12 15 20 21 19])

// calculate the difference in bid quantities between left and right
$ leftBidQty.rowAt(leftIndex).nullFill(0) - rightBidQty.rowAt(rightIndex).nullFill(0)
[[-8,-2,-5,3,12],[-10,7,-15,-3,7],[-12,7,-15,-12,-21,-10]]

$ leftIndex, rightIndex = rowAlign(left, right, "allBid")
$ leftIndex
[[-1,0,1,2],[-1,-1,0,1,2],[-1,0,-1,1,2]]

$ rightIndex
[[0,1,2,-1],[0,1,2,-1,-1],[0,-1,1,2,-1]]
$ left = array(DOUBLE[], 0, 3).append!([8.99 9.00 9.01, 8.97 8.99 9.00, 8.95 8.97 8.99])
$ right = array(DOUBLE[], 0, 3).append!([9.00 9.01 9.02, 8.99 9.00 9.01, 8.97 8.98 9.00])
$ leftIndex, rightIndex = rowAlign(left, right, "ask")
$ leftIndex
[[0,1,2],[0,1,2],[0,1,-1,2]]

$ rightIndex
[[-1,0,1],[-1,0,1],[-1,0,1,-1]]

$ leftIndex, rightIndex = rowAlign(left, right, "allAsk")
$ leftIndex
[[0,1,2,-1],[0,1,2,-1],[0,1,-1,2,-1]]

$ rightIndex
[[-1,0,1,2],[-1,0,1,2],[-1,0,1,-1,2]]