# Mitigating gateway delay

A trading system has $n$ colocated uplinks to TCP order entry gateways $g_1, \dots, g_n$ on a given exchange. Each gateway $g_i$ has a different order entry delay function $d_i(t)$ as a function of time $t$. (Note that I don't explicitly know the $d_i(t)$.)

The game is to build a sample function $S(t)$ which picks a gateway $g_i$ minimising order entry delay at time $t$.

What realtime statistical tests can be applied to the gateways to build a good sampling function $S$? (With TCP, it's easy to measure round-trip times since every message is ACKed.)

-
This is not my area of expertise but I do wonder: don't you want to specify some loss function? Maybe you want to punish long delays more or after a certain amount of delay it doesn't matter any more. –  Bob Jansen Nov 11 '13 at 13:30

If I understand correctly the TCP roundtrip time can be used as a posteriori proxi for the order entry gateway delay.

So assuming the roundtrip time is composed of gate delay and independent other delays $RTT_g(t) = dT_g(t) + d_g(t)$ with assumed $Cov(dT_g,d_g)=0$ and $Cov(d_i,d_j)=0$. Minimizing the this combination of gate delay and other delays is leading to the same goal.

Perhaps a univariate modeling of this $RTT_g(t)$ based on historical observed observations is suitable. Could be that a simple rolling mean/median and (robust) dispersion metric is enough?

I found this http://www.eecis.udel.edu/~bohacek/Papers/paper579.pdf paper about video streaming and congestion. They estimate a Cox-Ingersoll-Ross model (https://en.wikipedia.org/wiki/Cox%E2%80%93Ingersoll%E2%80%93Ross_model) to estimate and predict delays.

$dRTT_g = a (b-RTT_g)dt+\sigma\sqrt{RTT_g}dW_t$ with $dW_t$ brownian.

for this CIR there exist close form solutions for predictions which are chi-square family. so something like $S(t)=\text{argmin}_g \hat{RTT_g}(t+1)$

Note that i dont know if these gateway independence assumptions are not too strong, and i wonder if the gateway delay is not also a function of e.g. ordersize or previous usage. Good luck!

-

I think just picking minimum value for $d_i(t)$ will work optimal here, just how calculate that $d()$ function matters more, this can be last order delay from that gateway or some EMA of last X order delays. Important is query each gateway every some amount of time to prevent blocking gateway by one big anomaly delay that prevent $S(t)$ function from selecting that gateway in future. $$S(t) = g(\operatorname{argmin}_g d_g(t))$$

-
I don't know the $d_i(t)$! I need statistical tests to model them. That's basically the question. –  Randomblue Nov 9 '13 at 12:43