#### Topic: Combinatorics (from three fingers)

Therefore I have a small problem which I should optimize how much to a smog. My Universe contains N securities (N enough small, from 4 that 9). During each moment of time I receive the market quotation or the paper X, or spread S between two these securities. If I receive the spread quotation (i.e. a difference between two securities), I can calculate the synthetic price for two securities on a basis and the last quotations for each of papers i, j://S (i, j) = X (i) - X (j) bid [i] = q [BID] - bid [j] ask [i] = q [ASK] - ask [j] ask [j] =-q [BID] - ask [i] bid [j] = q [ASK] - bid [i] I need to support optimally current highest rates, and the lowest requirements to these securities. In terms of the pseudocode I did till now the following: B [n x n] = [-9999...,-9999] A [n x n] = [9999..., 9999] BX [n x n] = [0..., 0] AX [n x n] = [0..., 0] best_bid (q): if type (q) = security://simple case i = q [IDX1] B [0 to N, i] = q [BID] A [0 to N, i] = q [ASK] if type (q [i]) = spread://S (i, j) = X (i) - X (j) i = q [IDX1] j = q [IDX2] BX [i, j] = q [BID] BX [j, i] =-q [ASK] return max_col (B + BX)//max value of each column in an element-wise addition Too-most I do for other side. Such perversion works, but brakes since I am forced to do iteration on all matrix on each step (max_col). Cleverer ideas at me does not arise yet. Can at whom there are thoughts?