This question is related to Steady state of a non-trivial Markov chain. .
In a financial exchange customers submit orders which can be roughly divided into three types.Firstly, there are limit orders which are defined as requests to buy (sell) a given number of contracts (to be termed the order size) of an underlying asset provided the bid (ask) price is not bigger (not smaller ) than a given price specified by the customer (limit price). Clearly depending on different things (limit price, number of pending orders,etc.) it will take some time to execute a limit order. Secondly, there are market orders which are defined as requests to buy (sell) as soon as possible at the best price. As opposed to limit orders market orders are executed instantly.Thirdly, there are cancellations of already submitted limit orders with the likelihood of cancellations increasing monotonically with the number of pending orders. At any given time the pending sell orders (asks) and the pending buy orders (bids) are stored in the Limit order book. It is now our aim to describe the shape of the order book. To be specific we will be asking the following question. What is the probability that at time $t$ the total number of sell orders, whose limit prices are smaller equal $k_+$, is equal to $n_+$ and that the total number of buy orders, whose limit prices are bigger equal $k_-$, is equal to $n_-$. We denote the quantity in question as $p_{(n_+,n_-)}^{(k_+,k_-)}(t)$. By generalizing the model in 1 we write down the following master equation for the evolution of that bi-variate probability function. We have: \begin{eqnarray} &&p_{(n_+,n_-)}^{(k_+,k_-)}(t+1)=\\ &&p_{(n_++1,n_-)}^{(k_+,k_-)}(t) \cdot {\mathcal C}(n_++1) \cdot \lambda^C_+ + p_{(n_+,n_-+1)}^{(k_+,k_-)}(t) \cdot {\mathcal C}(n_-+1) \cdot \lambda^C_- +\\ &&p_{(n_++1,n_-)}^{(k_+,k_-)}(t) \cdot \lambda^M_+ + p_{(n_+,n_-+1)}^{(k_+,k_-)}(t) \cdot \lambda^M_- +\\ &&\Lambda_{+,k_+}^L \cdot \sum\limits_{i=1}^{n_+} p_{(n_+-i,n_-)}^{(k_+,k_-)}(t) \cdot G^{k_+}_i +\Lambda_{-,k_-}^L \cdot \sum\limits_{i=1}^{n_+} p_{(n_+,n_--i)}^{(k_+,k_-)}(t) \cdot G^{k_-}_i +\\ &&p_{(n_+,n_-)}^{(k_+,k_-)}(t)\cdot \left[ 1- \left( \lambda_+^M 1_{n_+ \ge 1} + \lambda_-^M 1_{n_- \ge 1} + {\mathcal C}(n_+) \cdot \lambda^C_+ + {\mathcal C}(n_-) \cdot \lambda^C_- + \Lambda^L_{+,k_+} +\Lambda^L_{-,k_-} \right) \right] \end{eqnarray} The terms in the right hand side have the following interpretation.We go from top down. The two terms in the second line describe a cancellation of a sell and a cancellation of a buy respectively wih ${\mathcal C}(n)$ being the likelihood of cancellation as a function of pending orders in the book $n$. Now, the two terms in the third line describe an annihilation of a sell (buy) by a buy (sell) market order. Then the two terms in the fourth line describe a deposition of a sell (buy) limit order of size $i$ in the order book on the ask (bid) side respectively with $G^{k_+}_i$ ($G^{k_-}_i$) being the probability that the limit sell (buy) order at price smaller equal $k_+$ (bigger equal $k_-$) is of size $i$. Here we assume that those probabilities are drawn from the negative binomial distribution, i.e. $G^{k_\pm}_i=q_\pm \cdot (1-q_\pm)^{i-1}$ for $i=1,\cdots,$. Finally the term in the fifth line describes the probability that nothing happens.
Now, having written the master equation it would be tempting to find the whole time dependent solution but we will make do with the steady state only. We have: \begin{equation} \lim_{t\rightarrow \infty} p_{(n_+,n_-)}^{(k_+,k_-)}(t) = X^{\left(q_+, \frac{\lambda^M_+}{\lambda^C_+}, \frac{\lambda^L_{+,k_+}}{\lambda^C_+}\right)}(n_+) \cdot X^{\left(q_-, \frac{\lambda^M_-}{\lambda^C_-}, \frac{\lambda^L_{-,k_-}}{\lambda^C_+}\right)}(n_-) \end{equation} where \begin{eqnarray} {\mathfrak N}^{(q,\lambda^M, \Lambda^L_k)} \cdot X^{(q,\lambda^M, \Lambda^L_k)}(n) := (1-q)^n \cdot \prod\limits_{j=1}^n \left( \frac{\frac{\Lambda^L_k}{1-q} +\lambda^M + {\mathcal C}(j-1)}{\lambda^M + {\mathcal C}(j) } \right) \cdot \left[ 1_{n=0} + \frac{\Lambda^L_k}{\Lambda^L_k + \lambda^M \cdot (1-q)} \cdot 1_{n\ge 1}\right] \end{eqnarray} and the normalization constant ${\mathfrak N}^{(q,\lambda^M, \Lambda^L_k)}$ reads: \begin{eqnarray} {\mathfrak N}^{(q,\lambda^M, \Lambda^L_k)}:= q \cdot F_{\theta+1,\theta} \left[ \begin{array}{rr} 1 & \left( 1 - \zeta_\xi (\lambda^M+\frac{\Lambda^L_k}{1-q}) \right)_{\xi=0}^{\theta-1} \\ & \left( 1 - \zeta_\xi (\lambda^M) \right)_{\xi=0}^{\theta-1} \end{array}; 1-q \right] \end{eqnarray} where the quantities $\left(\zeta_\xi(x)\right)_{\xi=0}^{\theta-1}$ are roots a a polynomial equation of order $\theta$, i.e.: \begin{equation} {\mathcal C}(\zeta_\xi(x)) + x = 0 \quad \mbox{for $\xi=0,\cdots,\theta-1$} \end{equation} and $F_{\theta+1,\theta} \left[ \right]$ is the generalized hypergeometric function. Below is a MATHEMATICA code snippet that verifies this solution along with with a contour plot of the bi-variate probability distribution. We have:
In[2169]:= lCp =.; lMp =.; Lp =.; qp =.;
lCm =.; lMm =.; Lm =.; qm =.; M = 200; th = 1;
{lCp, lMp, Lp, qp} =
RandomReal[{0, 1}, 4, WorkingPrecision -> 50]; {lCp, lMp, Lp,
qp} = {1, 1 10^(-6), 3.1, 2 10^(-2)};
{lCm, lMm, Lm, qm} =
RandomReal[{0, 1}, 4, WorkingPrecision -> 50]; {lCm, lMm, Lm,
qm} = {1, 2 10^(-6), 1.51, 1 10^(-2)};
P = Table[0, {i, 1, M}, {j, 1, M}];
coeffs = RandomInteger[{1, 10}, th];
cLHd[n_] :=
n^Range[1,
th] .coeffs;(*Cancellation likelihood as a function of pending \
orders in the book.*)
cLHd[n_] := n;
mySol[n_, q_, lM_, L_] :=
If[n == 0,
1, (1 - q)^n Product[L/(1 - q) + lM + cLHd[j], {j, 0, n - 1}]/
Product[lM + cLHd[j], {j, 1, n}] L/( L + lM (1 - q)) ];
x =.;
{rts0, rts1} = {x /. NSolve[cLHd[x] + lMp/lCp == 0, x],
x /. NSolve[cLHd[x] + (Lp/lCp)/(1 - qp) + lMp/lCp == 0, x]};
NNp = qp HypergeometricPFQ[
Join[{1}, Table[1 - rts1[[xi + 1]], {xi, 0, th - 1}]],
Table[1 - rts0[[xi + 1]], {xi, 0, th - 1}], 1 - qp];
{rts0, rts1} = {x /. NSolve[cLHd[x] + lMm/lCm == 0, x],
x /. NSolve[cLHd[x] + (Lm/lCm)/(1 - qm) + lMm/lCm == 0, x]};
NNm = qm HypergeometricPFQ[
Join[{1}, Table[1 - rts1[[xi + 1]], {xi, 0, th - 1}]],
Table[1 - rts0[[xi + 1]], {xi, 0, th - 1}], 1 - qm];
P = 1/(NNp NNm)
Table[mySol[np, qp, lMp/lCp, Lp/lCp] mySol[nm, qm, lMm/lCm, Lm/
lCm], {np, 0, M - 1}, {nm, 0, M - 1}];
rhs = Table[
P[[np + 2, nm + 1]] cLHd[(np + 1)] lCp +
P[[np + 1, nm + 2]] cLHd[(nm + 1)] lCm +
P[[np + 2, nm + 1]] lMp + P[[np + 1, nm + 2]] lMm +
Lp Sum[P[[np + 1 - i, nm + 1]] qp (1 - qp)^(i - 1), {i, 1, np}] +
Lm Sum[P[[np + 1, nm + 1 - i]] qm (1 - qm)^(i - 1), {i, 1, nm}] +
-P[[np + 1, nm + 1]] (lMp If[np >= 1, 1, 0] +
lMm If[nm >= 1, 1, 0] + cLHd[ np] lCp + cLHd[nm] lCm + Lp + Lm)
, {np, 0, M - 2}, {nm, 0, M - 2}];
Total[Flatten[Abs[rhs]^2]]
Flatten[P] // Total
ListContourPlot[P, Contours -> 5, ContourLabels -> True,
FrameLabel -> {"np", "nm", "P[np,nm]"}]
Out[2184]= 8.52128*10^-32
Out[2185]= 0.544696
In plotting the bi-variate probability distribution above we took $(\lambda^C_+,\lambda^M_+,\Lambda^L_{+,k+})=(1, 1 10^{-6}, 3.1, 2 10^{-2})$ and $(\lambda^C_-,\lambda^M_-,\Lambda^L_{-,k-})=(1, 2 10^{-6}, 1.51, 1 10^{-2})$.
Now, having said all this it is time to ask a question. First of all is this model generalization realistic? Note that we assumed that cancellations of orders on one side of the book depend only on the number of orders pending on that very side of the book and not on the orders pending on the other book side, i.e. cancellations of sell orders only depend on pending sell orders and not on buy orders. Is this assumption realistic or otherwise how should it be modified to describe reality better? Now, the second question would be what is the best way to calibrate this model to market data. Shall we be matching the moments of the distribution or minimizing the log-likelihood or maybe still during something else? If we were to match the moments what are the closed form expressions for them.
1 "A Model with Varying Sizes of Limit Orders" in F Abergel et al, Limit Order Books, Cambridge University Press 2016, section 7.4, page 88
