{'fraction_non_alphanumeric': 0.04595553542445174, 'fraction_numerical': 0.018268976710829277, 'mean_word_length': 4.004438987533057, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 53, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Market Making with Stochastic Liquidity Demand: Simultaneous Order Arrival and Price Change Forecasts

We provide an explicit characterization of the optimal market making strategy in a discrete-time Limit Order Book (LOB). In our model, the number of filled orders during each period depends linearly on the distance between the fundamental price and the market maker's limit order quotes, with random slope and intercept coefficients. The high-frequency market maker (HFM) incurs an end-of-the-day liquidation cost resulting from linear price impact. The optimal placement strategy incorporates in a novel and parsimonious way forecasts about future changes in the asset's fundamental price. We show that the randomness in the demand slope reduces the inventory management motive, and that a positive correlation between demand slope and investors' reservation prices leads to wider spreads. Our analysis reveals that the simultaneous arrival of buy and sell market orders (i) reduces the shadow cost of inventory, (ii) leads the HFM to reduce price pressures to execute larger flows, and (iii) introduces patterns of nonlinearity in the intraday dynamics of bid and ask spreads. Our empirical study shows that the market making strategy outperforms those which ignores randomness in demand, simultaneous arrival of buy and sell market orders, and local drift in the fundamental price.


Introduction
Since the last decade, most security trading activities have migrated to electronic markets and, as a result, high frequency trading has become one of the most significant market developments.
Estimates of high frequency volumes in the treasury, foreign exchange, equity and index futures markets are typically several deciles of the total traded volume (Joint Staff Report (2015); Markets Committee et al. (2011); Securities and Exchange Commission (2010); Kirilenko et al. (2017)). As observed by Menkveld (2013), market making activities are being predominantly carried out by high-frequency traders. A traditional market maker provides liquidity to the exchange by continuously placing bid and ask orders, and hence, earning profit from the bid-ask spread of her quotes.
Like traditional market makers, high frequency market makers (HFMs) make profit from roundtrip transactions but, unlike traditional market makers, they also submit numerous passive orders that are canceled shortly after submission at extraordinary high-speed (Securities and Exchange Commission (2010)). More importantly, compared with traditional market makers, HFMs typically work at privately held firms and, thus, inventory control becomes necessary for them to limit the amount of capital tied up in margin accounts (Menkveld (2016)). The practice of ending the day close to a flat position is also driven by risk management motives, as it allows the market maker to reduce uncertainty coming from fluctuations in security prices at the beginning of the next trading day.
Existing literature has analyzed market making control problems with inventory risk. The study of Ho & Stoll (1981) considers a single period mean-variance utility for a market maker wishing to optimize expected profit from bid-ask spreads, and to find offsetting transactions to minimize inventory risk. Huang et al. (2012) consider risk-averse market makers with single period meanvariance or exponential utility who use a threshold inventory control policy to reduce the risk from price uncertainty. Due to the static nature of their setup, these studies do not analyze the intraday effects of orders arrival and inventory management on prices and liquidity.
Other studies have considered dynamic models of market making. Some of them aim to penalize intraday inventory holdings (see e.g. Cartea et al. (2014), Cartea & Jaimungal (2015) for contri-butions in this space). 1 Other studies impose explicit constraints on terminal inventory. Examples of those works include the early contributions of Bradfield (1979), who analyze the increasing price variability induced by strategies that target a flat end-of-day inventory level; O' Hara & Oldfield (1986), who consider a repeated optimal market making problem, in which each day consists of several trading periods, and the market maker maximizes utility over an infinite number of trading days while facing end-of-day inventory costs; Guéant et al. (2013), who sets the penalty for end of day inventory to be proportional to the absolute value of the terminal inventory; and the most recent study of Adrian et al. (2020), who study intraday patterns of prices and volatility induced by inventory management motives with focus on the Treasury market. 2 We solve a discrete-time optimal control problem to maximize expected cumulative profits of the market maker, while incorporating an end-of-the-day inventory liquidation cost. Such a cost is driven by the assumption of a linear instantaneous price impact: the average price per share in liquidating an inventory of size I T at time T is S T − λI T , where S T is the fundamental price at time T (typically, the asset's midprice) and λ is a constant penalty. In our framework, the HFM places limit orders (LOs) on the ask and bid sides simultaneously, and cancels the remaining unexecuted quotes shortly before submitting new quotes in the book. Her wealth and inventory trajectory are hence determined by the prices of her quotes and the number of shares that are filled or lifted from her orders at these prices.
Modeling the number of lifted shares between consecutive actions is a key component of our framework. In continuous-time control problems, a common approach is to model the probability with which an incoming market order (MO) can lift one share of the HFM's LO in the book (known as 'lifting probability'). For instance, Cartea et al. (2014); Cartea & Jaimungal (2015) assume that the MOs arrive according to a Poisson process and model the lifting probability as the exponential of the negative distance of the HFM's quote from the midprice times a constant; Cvitanic & Kirilenko (2010) instead model the lifting probability with a linear function, assuming 1 Amihud & Mendelson (1980) assume a dynamic model in which dealers are risk neutral and buy and sell orders arrive according to a Poisson process with price-dependent rates. They consider an infinite time horizon and restrict inventory levels to be inside a prespecified interval throughout the entire trading day.
2 Few empirical studies have analyzed the relationship between trades, prices and bid-ask spreads using transaction data. Glosten & Harris (1988) and Hasbrouck (1988) decompose bid-ask spreads into two components, reflecting compensation for inventory costs and adverse selection costs, which arise from the presence of informed traders. They find that, in contrast to the transitory spread component explained by inventory considerations, the permanent component explained by information asymmetries is significant for large trades but not for small ones.
the MOs to be uniformly distributed on a preset price interval. An alternative approach, especially predominant in discrete-time control problems, is to directly model the number of lifted shares via a liquidity demand function. For instance, in their work on price pressures, Hendershott & Menkveld (2014) assume that the liquidity demand is normally distributed with a mean that is linear in the bid and ask price. A continuous time stochastic model of a limit order book, which mimics a queuing system where limit orders are executed against market orders, has been proposed by Cont et al. (2010). Unlike ours, their work does not consider inventory costs. 3 The exponential lifting probabilities used in continuous-time control problems can be related to the linear demand function used in discrete problems. Specifically, if ρ is the arrival intensity of MO's and the lifting probability is set to be exp(−κd), where d is the distance between the LO price and the midprice, then, during a time span of ∆, we expect that ∆ρ exp(−κd) times a MO will lift a LO placed at distance d. Since it is typically assumed that only one share of the order is lifted at a time, when d is small (as it is commonly the case), the expected number of shares filled during that time span is approximately equal to ∆ρ − ∆ρκd, which is precisely linear in d.
Note, however, that the previous argument assumes that a LO with volume Q ∈ N is treated as Q independent LOs of volume one with the same lifting probability, which is not the case in practice.
Our work extends existing models of high-frequency market making in several ways. We assume the demand to be linear when modeling the number of filled shares from the HFM's limit orders.
However, unlike Adrian et al. (2020) and Hendershott & Menkveld (2014), the demand is not deterministic but random. This means that the actual number of shares bought or sold varies over time, even if the distances of quotes from the fundamental price stay the same. The proposed randomization not only allows for greater flexibility and better fit to empirically observed order flows, but also uncovers novel properties of the resulting optimal placement strategies. For instance, it is known from Adrian et al. (2020) that, under a constant demand slope, the inventory adjustment in the optimal placement at any given time decreases with the size of the slope. We show that the variance of the slope further reduces this adjustment. This implies that assets with highly volatile demand profiles require less strict inventory adjustments. We also find that the optimal placement 3 A separate stream of literature has analyzed liquidity in a limit order book with endogenous equilibrium dynamics. See, for instance, Gayduk & Nadtochiy (2018). spreads (i.e., the distances between the optimal bid and ask prices and the fundamental price) increase with the correlation between demand slope and investors' reservation price.
To the best of our knowledge, our framework is the first to incorporate simultaneous arrivals of buy and sell MOs between consecutive market making actions. The time-discretized version of most existing models (e.g. Adrian et al. (2020) and Cartea & Jaimungal (2015)), which are obtained from the continuous-time versions via Euler approximations, does not allow for this feature. We first obtain a closed form expression for the optimal strategies that explicitly account for the probability π(1, 1) of simultaneous arrivals of buy and sell MOs during each small time period. We then perform a comparative statics analysis, and discover novel patterns of optimal placements strategies.
First, at any given time we find that the optimal bid-ask spread declines if π(1, 1) increases.
The intuition is that a higher likelihood of simultaneous buy and sell orders arrival provides the HFM with more opportunities to manage inventory: the positive net position resulting from the execution of sell MOs offsets the negative net position corresponding to the execution of buy MOs.
Second, we show that bid-ask spreads are less sensitive to the passage of time as π(1, 1) increases.
Interestingly, if π(1, 1) is sufficiently large, the bid-ask spread no longer rises towards the end of the day. This intraday pattern stands in contrast with that identified by Adrian et al. (2020), and can be understood as follows. While the need of reaching a zero inventory target becomes stronger with passage of time, a larger arrival rate of offsetting buy and sell MOs reduces the shadow cost of endof-the-day inventory and incentivizes the HFM to reduce price pressures for attracting larger flows.
Third, we show that the presence of simultaneous arrivals introduces a nonlinearity in the intraday dynamics of bid spread and ask spread. In the absence of simultaneous arrivals, the ask spread and bid spread (i.e., the distances of the HFM's optimal ask and bid quotes from the fundamental price) are decreasing functions of time. However, if π(1, 1) = 0, this monotonicity is broken as we get closer to the end of day. Last, but not least, we observe a novel threshold phenomenon in the HFM's inventory management: if inventory holdings are below a certain threshold, the HFM widens her bid and ask spread to dampen trading activity on both sides of the market and preserve the current inventory position, instead of aggressively placing LOs close to the security price to lower her net position.
Another distinguishing and novel feature of our study, relative to the rest of literature, is that we allow the market maker to incorporate forecasts about the fundamental price of the asset, rather than assuming martingale dynamics. We obtain a parsimonious formula which describes how the investor should adjust her limit order placements based on her asset price forecasts. Intuitively, if the HFM expects future price changes to be negative, she would reduce the bid and ask spread proportionally to the expected price change. The proportionality constant depends on the model parameters in a non-trivial way. This feature also allows the investor to take advantage of sophisticated time series-or machine learning-based forecast procedures of asset prices into the intraday market-making process (see Section 3 for the technical details).
To the best of our knowledge, our work is unique in that it assesses the performance of the proposed market making strategy against LOB data. Specifically, we first use a rolling window approach to estimate the model parameters. We then test the calibrated model against actual LOB dynamics, allowing for adjustments of LO's placements every second and determining the cash flows and inventory changes generated during the day. At day's close, the HFM submits a MO to liquidate its final inventory, and determine the actual cost taking into account the state of the LOB. We find that the optimal placement yields, on average, larger revenue compared to the situation where π(1, 1) = 0 (such as in Adrian et al. (2020)), even if π(1, 1) is estimated to be small and about 0.05. Our empirical analysis lends strong support to demand stochasticity: the slope coefficient has a standard deviation which is about 200% larger than the average demand level, and a correlation of about 20% with the investors' reservation price. Moreover, using real LOB data we estimate the optimal placement strategy based on a simple one-step ahead forecast to outperform the one that presumes a martingale price evolution.
The solution of the optimal control problem presents nontrivial mathematical challenges. While the first-order optimality conditions involves solving a quadratic equation, establishing the secondorder conditions needed for the verification theorem is intricate. It involves establishing several clever estimates, in which we leverage direct inequalities implied by the primitives of our model. The rest of the paper is organized as follows. In Section 2, we present the model setup together with our assumptions. Section 3 solves the Bellman equation for the control problem, and proves a verification theorem. In Section 4, we analyze in detail the main economic forces behind the optimal placement strategies. In Section 5, we measure the performance of our market making strategy against real LOB data. We delegate technical proofs to two appendices.

Model Setup
In this section we introduce our Limit Order Book (LOB) model and specify the type of considered strategies. We assume the market making strategy runs from time 0 to a fixed time T > 0.
The HFM places bid and ask limit orders (LO) simultaneously on both sides of the LOB for a given asset at preset times 0 = t 0 < t 1 < · · · < t N < T . Throughout, we set t N +1 = T and T = {t 0 , t 1 , . . . , t N +1 }. All variables introduced below are assumed to be defined on a probability space (Ω, P, F) equipped with a filtration {F t } t∈T , which represents the arrival of market makers' available information through time.
Arrivals of buy and sell market orders (MO) are modeled by two Bernoulli processes. Specifically, let 1 + hold for each t k+1 : The ask (bid) LO is placed at time t k , k = 0, . . . , N , at the price level a t k ∈ F t k (b t k ∈ F t k ).
We parameterize a t k and b t k as where L ± t k ∈ F t k are the market maker's spreads and S t k ∈ F t k is the fundamental price of the asset at time t k . The assumptions on the fundamental prices process {S t k } k=0,...,N +1 are further specified in Section 3.
The limit orders placed at time t k may be fully or partially executed during the time interval [t k , t k+1 ), but only if there exists at least one arrival of a market order during that period. We assume that the number of filled shares on the bid side during the interval [t k , t k+1 ) is given by Price Number of filled shares is the lowest price that a sell market order can attain, and S t k + p + t k+1 is the highest price that a buy market order can attain during the time interval [t k , t k+1 ). The number of filled shares increase as the market maker places limit orders closer to the fundamental price S t k . The number of filled shares Q ± t k+1 is illustrated in Figure 1. The quantity Q ± t k+1 may be viewed as the "best" linear fit for the actual demand as shown in Figure 2. More details on the estimation of Q ± t k+1 are covered in the empirical analysis conducted in Section 5.
Next, we state our main assumptions on c ± . and p ± . .
Assumption 1 (General Properties of (c ± . , p ± . )) For k = 0, . . . , N , we have: Next, we introduce some further notation related to (c ± . , p ± . ): We consider the following maximization problem for the HFM: where A is the collection of all F-adapted processes, and W T and I T stand for the market maker's cash holdings and inventory at the end of period [0, T ], respectively. The cash holding and inventory processes, {W t k } and {I t k }, respectively, satisfy the following equations: where W t 0 = 0 and I t 0 = 0.
The term λI 2 T ≥ 0 in the maximization problem (9) is the cost for holding inventory at the terminal time T . This formulation captures, in reduced form, the fact that HFMs tend to have de minimis balance sheets, thus making any overnight inventory costly to carry. 4 The penalty term for holding end-of-day inventory can also be interpreted as follows. We can rewrite the last two terms S T I T − λI 2 T in the above expectation as (S T − λI T )I T . Then, S T − λI T is the average price per share that the HFM will get when liquidating her inventory I T via a MO, under the assumption of a linear instantaneous price impact. For instance, if I T > 0 (I T < 0), then the HFM will have to submit a sell (buy) MO, which will result in eating into the bid (ask) side of the book. We will validate the assumption of linear price impact in Section 5.

The Bellman Equation for the Control Problem
At time t k , the value function of the control problem described above is given by By the dynamic programming principle, we obtain it satisfies the following equation We now proceed to find the optimal placement strategy for the market maker. Our objective is to derive it for a general adapted stochastic process of the fundamental price. To illustrate the procedure behind the construction, we first analyze the setting where the fundamental price process is a martingale, and obtain tractable formulas for the optimal bid and ask prices and the value function (see Subsection 3.1). In Subsection 3.2, we relax the martingale assumption and provide a general formula for general adapted stochastic price dynamics of the fundamental price.

Optimal Strategy Under a Martingale Fundamental Price Process
In this subsection, we assume that the fundamental price S t k ∈ F t k of the asset is a martingale: Furthermore, we assume that S t k+1 − S t k and (1 + where α : T → R, h : T → R, and g : T → R are deterministic functions defined on T = We can determine the functions α . , h . , and g . by plugging the ansatz (15) back into Eq. (13), and then using Eqs. (10)-(11). This yields the following iterative representation for the value function where the coefficients above are specified as (1) (3) In the expressions above, α : T → R and h : T → R are specified using the following backward and, for k = 0, . . . , N : and where a * t k is the price for the ask limit order and b * t k is the price for the bid limit order.
Recall that We next prove a verification theorem for the optimal placements given in Eq. (17). Its proof is Theorem 1 (Verification Theorem) The optimal value function V t k of the control problem (23) is given by with α t k and h t k given in Proposition 1, and g t k defined as g T = 0 and, for k = 0, . . . , N , Furthermore, the optimal controls are given by L ±, * . as defined in (17).

Optimal Strategy with a General Adapted Fundamental Price Process
In this subsection, we relax the martingale assumption on the fundamental price process {S t k } t k ∈T made in the previous subsection, and consider a general adapted process. Furthermore, we assume The variable ∆ t k reflects the HFM's forecast about the asset price's change in the interval [t k , t k+1 ) based on her information available at t k . Including this term makes our model more flexible and, as we shall see in Section 5, the resulting optimal placement strategies achieve better empirical performance. We leave the rest of the model setup as in Section 2.
We define the price change forecasts and recall the standard convention k−1 =k = 1. The following result gives the optimal placement spreads for an arbitrary adapted price process {S t k } t k ∈T in terms of the forecasts (24) and the optimal placement strategy L ±, * t k of Proposition 1. The proof is provided in Appendix A.1.
Theorem 2 (Optimal Controls with a General Adapted Fundamental Price Process) The optimal controls which solve the dynamic optimization problem (16) are given, for k = 0, . . . , N , by where β ± t k and γ t k are the deterministic sequences introduced in Proposition 1, and L ±, * t k are the optimal spreads defined therein. The quantity ξ k is defined as: of each trading day. That is to say, all parameters needed to compute L ±, * t k (i.e., the optimal controls with a martingale price process) are predetermined at the beginning of the day. Second, we solve the forecasting problem of determining {∆ t k t j } j=k,...,N , and compute L ±, * t k using the expression of L ±, * t k as in Eq. (25). This task is done "online" at each time t k . Thus, under a general adapted fundamental price process, the optimal strategy L ±, * t k incorporates the views of the HFM about changes in the fundamental based on her information available at time t k .
Remark 2 As shown in Appendix A.1, for the case of a general adapted price process {S t k } t k ∈T , the ansatz for the value function V t k takes the form: are now processes adapted to the filtration {F t } t∈T . The precise expressions for h and g are given in Eqs. (A-15)-(A-16) using notation (A-2). The proof of the corresponding verification theorem proceeds along similar lines as the proof of Theorem 1.
In the next proposition, we provide conditions under which the bid-ask spread is guaranteed to be positive (i.e., a t k > b t k ). We defer the proof to Appendix A.4.
Proposition 2 (Conditions for a Optimal Positive Spread) Under both martingale and nonmartingale price processes, the optimal placement strategy yields positive spreads at all times (i.e., a t k > b t k , for all k = 0, . . . , N ), provided that the following three conditions hold: (1) The first and second conditional moments of c ± defined in Eq.(8) satisfy (2) Buy and sell market orders arrive with the same probability: (3) The conditional expectations of (cp) ± and (c 2 p) ± defined in Eq.(8) satisfy where µ ± p := E(p ± indicates whether there are arrivals of buy (sell) MOs during [t k , t k+1 ). If π t k+1 (1, 1) = 0, it follows from Eq. (27) that the best placement strategies take the following form: where and ξ 0 k is given by Eq. (26), setting π t k+1 (1, 1) = 0 therein.
The second term in (32)-(33) is the adjustment for inventory holdings, whose coefficient is negative because α 0 t k+1 < 0 per Lemma 1. This is intuitive, because when the inventory is positive (negative), the bid and ask placements decrease (increase) to attract more sales (purchases) of the stock. The shadow cost of inventory is low for most of the day and only becomes significant near the end. This is because, as shown in Fig. 3, α 0 k is close to 0 for most of the day and decreases rapidly to −λ near the end. It is also interesting to note that the variance of c, which is the random slope in the linear demand function, reduces the shadow cost of inventory because the coefficient of I t k can be written as: Figure 3: Paths of α 0 t k and h 0 t k in a Symmetric Market. The action times are chosen to be each second from time 0 to 19800 seconds (5.5 hours). λ = 0.0005. We choose the parameters so that Conditions (29)-(30) slope c ± t k . As a result, more shares of the HFM's LOs will be executed (see Fig. 1) and, hence, the HFM can act less 'aggressively' when attempting to zero out her inventory. The feature just described cannot be captured by linear demand functions with deterministic slope as in Hendershott & Menkveld (2014) and Adrian et al. (2020). We provide further analysis on the sensitivity of the optimal strategy to the inventory cost in Subsection 4.2.
If t k is far from the terminal time T and the market is reasonably "symmetric" 5 , the sequences α 0 t k and h 0 t k defined in Eq. (34) are close to zero most of the time (see Fig. 3). The optimal strategy is then mainly dependent on the second term of L ±, * ,0 t k and the drift ∆ t k in the price dynamics of S t k . It follows from (32)-(33) that where recall that µ ± p = E(p ± t k+1 |F t k , 1 ± t k+1 = 1). The correlation between c and p now plays a key role in the optimal placements. Under the martingale Condition (14) and under Condition (31), the last two terms in the optimal placements become zero. The optimal placements are then near the midpoint between S t k and S t k ± µ ± p for most of the time. However, when the correlation between c and p is positive, instead of placing LOs around S t k ± µ ± p /2, the HFM will tend to go deeper into the book. Roughly, a larger realization of c also implies a large value of p, resulting in a larger demand function and, hence, greater opportunity for the HFM to obtain better prices for her filled LOs. Another way to understand (36)-(37) is to recall that c ± p ± is the y-intercept of the demand functions (see Fig. 1) and, thus, the larger µ ± cp , the larger the demand function and the deeper the HFM could place her LOs. The discussion above holds for most of the day. However, when t k gets closer to T , the second term of (32)-(33) will play a more important role in the best strategy because α 0 t k+1 is no longer close to zero by end of the day. Hence, the optimal strategy is mostly influenced by the inventory level towards the day's end.
The probability π t k (1, 1) of simultaneous arrivals of buy and sell MOs during a time step is typically small at high-frequency trading (say, at 1 seconds or less). For the empirical analysis conducted in Section 5, we find that π t k (1, 1) ≈ 0.05 for a trading period of 1 second. However, this is no longer the case if the trading frequency is smaller (say, at 5 seconds or more). In that case, it is important to account for the event of joint arrivals. The following corollary sheds light on the optimal placement's behavior under conditions (29)-(31) plus additional conditions (which are reasonably met by our data in Section 5).
We prove Corollary 1 in Appendix B.1. We know that while the drift in the mid-price process and the HFM's net inventory position can affect the optimal bid and ask prices at any given time, the optimal spread is invariant to the specific value of the drift and inventory position. It can be seen from Fig. 4 that, as t k approaches the terminal time T , the optimal spread widens due to the penalty placed on the terminal inventory. By widening the optimal spread, the HFM attempts to trade predominantly on one side of the book (say, sell side if inventory is positive), so to control the inventory level. As π(1, 1) increases, the probability of simultaneous arrivals of buy and sell MOs increases, hence, providing more opportunities for the HFM to manage her inventory. This   (31) and (38) hold. Specifically, we set µ ± c = 100 , µ ± p = 5, µ ± c 2 p 2 = 1 × 10 5 , π + = π − = 0.2. π(1, 1) ranges from 0 to π ± . These parameter values are consistent with the empirical estimates obtained from our data and given in Section 5.

Sensitivity of the Optimal Strategies to Inventory Holdings
We now generalize the sensitivity analysis of optimal placements on inventory levels developed earlier for the case π(1, 1) = 0. We account for the nonzero probability of joint arrivals, i.e. for π(1, 1) > 0.
Corollary 2 The optimal ask price a * t k and bid price b * t k , as defined in Eq. (27), are strictly decreasing with inventory I t k .
The proof is given in Appendix B.2. Corollary 2 reflects the HFM's ability to control inventory through the optimal placement strategies under a general adapted fundamental price process. When the HFM has a large net long inventory position, she puts ask and bid quotes at lower price to accelerate selling and dampen buying activities. If instead the inventory position becomes large but net short, she will raise the bid and ask prices to accelerate buying and dampen selling. Fig. 5 plots the distance of the HFM's optimal ask and bid quotes from the fundamental price S t k within the last 500-seconds before the end of trading, for different inventory levels. As we mentioned in Subsection 4.1.1, if the market is reasonably "symmetric" and under the assumption that c and p are independent, the agent's optimal ask spread, a * t k − S t k , and bid spread, are close to µ + p /2 and µ − p /2, respectively, for most of the time, regardless the inventory level. We remark that µ ± p /2 equals 2.5 ticks under the parameter specification used to produce Fig. 5. By the end of trading, the optimal ask and bid prices become sensitive to the inventory level. The HFM then chooses from two different strategies depending on her inventory level: • If her inventory level is low (e.g., between −250 to 250 shares), the HFM will widen both bid and ask spreads to decrease both buying and selling, as t k approaches T and, hence, keep the inventory low till the end; • When her inventory level is high (e.g., outside −250 to 250 shares), the HFM will narrow her ask (bid) spread to facilitate selling (buying) of shares, while widening the bid (ask) spread to dampen buying (selling) with a large positive (negative) net position.
Thus, under the parameter specification used to produce Fig. 5, the inventory levels ±250 shares are boundaries for the different end-of-horizon behaviors as described above.

Sensitivity of the Optimal Strategies to Inventory Penalty
We first consider the case of π t k+1 (1, 1) = 0 under a symmetric market and martingale dynamics for the fundamental price process. The following result then characterizes the optimal placements relative to the baseline price level S t k ± µ p /2. The proof is given in Appendix B.3.  (31) and (38). Specifically, we set µ ± c = 100 , µ ± p = 5, µ ± c 2 p 2 = 1 × 10 5 , π + = π − = 0.2, π(1, 1) = 0, and λ = 0.0005. These parameter values are consistent with the estimates obtained from real data in Section 5.
Corollary 3 Assume the market is symmetric (i.e., Conditions (29)-(31) of Proposition 2 hold and that µ p := µ + p = µ − p ), and π t k+1 (1, 1) = 0 (i.e., only one type of MOs can arrive during each subinterval). Then, under a martingale fundamental price process, there exists a threshold for the inventory level, such that the following statements hold for every penalty term λ > 0: • When the inventory level I t k ∈ (I − , I + ), the optimal strategy is to place the ask and bid quotes deeper in the LOB relative to the levels S t k + µ p /2 and S t k − µ p /2, respectively; • When the inventory level I t k > I + (I t k < I − ), the optimal strategy is to place the ask (bid) quote closer to S t k than to S t k + µ p /2 ( S t k − µ p /2), and the bid (ask) quote farther from S t k than from S t k − µ p /2 (S t k + µ p /2) into the LOB.
It can be seen from Fig. 6 that if there is no inventory holding cost, the optimal strategy is to keep the ask and bid prices constant throughout the day, no matter how much inventory the HFM holds. With a larger penalty, a HFM with a positive net position will place her bid LOs deeper into the book near the end of the trading horizon to avoid more purchases of stock. For the ask side, she will pick one of three different strategies: (a) place the ask LO further from S t k , (b) place the ask LO closer to S t k , or (c) keep the ask LO at the same price level as earlier in the trading day. According to Corollary 3, the selection between (a), (b), or (c) depends on whether I t k > I + , I t k = I + , or I t k < I + , respectively. Under the parameter specification used to produce Fig. 6, we find that the threshold inventory is I ± = ±250.
The left panel of Fig. 6 shows the optimal placements when the position is net long. As the inventory approaches 100 holdings, the HFM places both bid and ask orders deeper into the book near the end of trading horizon in order to maintain the present inventory level. The larger the penalty for terminal inventory, the deeper she will go into the LOB on both sides. If the inventory consists of 250 shares, the left panel of the second row in Fig. 6 indicates that the optimal bid placement goes even deeper into the book, while the price trajectory of the optimal ask remains flat till the end of the trading horizon. If the inventory reaches the thresholdĪ ± , the strategy of the HFM is insensitive to the inventory penalty, no matter how large it is. However, when the inventory level reaches 500, the HFM needs to lower the optimal ask price in order to get more ask LOs executed and, hence, lower the inventory level. The higher the inventory, the closer she puts her ask quote to the mid-price. A similar discussion applies to the case of negative inventory positions, as shown in the right panel of Fig. 6.
However, if we allow for joint arrivals, i.e. π t k (1, 1) > 0, we can observe significant differences in the optimal strategies. Fig. 7 illustrates that, if π t k (1, 1) > 0, there does not exist an inventory level such that the optimal prices are flat throughout the trading horizon. Furthermore, for some inventory levels, the optimal strategies are no longer monotonic in time. We observe a valley (peak) pattern in the optimal ask (bid) placement for some positive (negative) intermediate inventory level.
Our intuition for this trading pattern is as follows. Consider, for example, the left panel in Fig. 7, where I t k = 250. If there is still enough trading time left, it is of higher priority for the HFM to sell more and lower the inventory level because there will be opportunities to buy later and profit from the roundtrip transaction. However, as the time gets closer to the terminal time T , it becomes more important to profit directly from less, but wider, roundtrip transactions because there is not enough time left for the market maker to conclude the roundtrip transaction. If buy and sell MOs can arrive simultaneously, roundtrip transactions are more likely to happen within two consecutive actions. Notice that as the penalty λ gets larger, the optimal strategy becomes more 'aggressive' Figure 6: Optimal strategies in the last 100 seconds, for various inventory and penalty levels. The action times are chosen to be each second. We let λ range from 0 to 0.01. We set µ ± c = 100 , µ ± p = 5, µ ± c 2 p 2 = 1 × 10 5 , π + = π − = 0.2, π(1, 1) = 0. These parameters satisfy Conditions (29)-(31) and (38). The parameter values are consistent with the estimates obtained from real data in Section 5.
because of the stronger incentives to make higher profits and compensate for the cost of holding terminal inventory. Figure 7: The last 100 seconds optimal strategies with various inventory and penalty levels. The action times are chosen to be every 1 second. λ ranges from 0 to 0.01. µ ± c = 100 , µ ± p = 5, µ ± c 2 p 2 = 1 × 10 5 , π + = π − = 0.2, π(1, 1) = 0.05 and the parameters satisfy Conditions (29)-(31) and (38). The values of the parameters are consistent with the estimates from real data given in Section 5.

Data Calibration and Performance Analysis
This section studies the performance of the optimal strategies derived in Section 3 using real LOB data. We first describe the data set and the parameter estimation procedure. We then present the performance analysis, and additionally compare the optimal strategy against "benchmark" strategies that place limit orders on fixed levels in the limit order book.
Data. We use of LOB data of the MSFT stock during the year of 2019 (252 days in total). Our data set is obtained from Nasdaq TotalView-ITCH 5.0, which is a direct data feed product offered by The Nasdaq Stock Market, LLC 6 . TotalView-ITCH uses a series of event messages to track any change to the state of the LOB. For each message, we observe the timestamp, type, direction, volume, and price. We reconstruct the dynamics of the top 20 levels of the LOB directly from the event message data. We treat each day as an independent sample.
Actions. We assume no latency in the HFM's actions and the HFM's order is always ahead of the queue of the LOs with same price in the LOB. We fix the action times for the HFM to be every second of a trading period running from 10:00 a.m. to 15:30 p.m. Thus, the HFM acts 19800 times in a regular trading day. At the beginning of each 1-second subinterval, the HFM places an ask and a bid LO, each of a fixed volume. The volume is set to be 500 shares, roughly matching the average volume of MOs arriving within 1-second intervals. The tick size of MSFT stock is one cent.
The calculated optimal ask (bid) price is round-up (down) to the nearest tick such that, in reality, the order can be executed at a better price while the filled size remains unchanged.
Historical Window Size for Parameter Estimation. The parameters plugged into the optimal strategy for the current day are estimated via historical averages including the prior 20 trading days.
(2)-(3), and the conditional expectations related to (c ± . , p ± . ), defined in Eq. (8). Because there is a total of 252 trading days in year 2019, we compute terminal revenues for 232 days, i.e., starting from the 21st trading day.

Parameter Estimation
Frequencies of MOs. During a typical trading day, sell and buy MOs usually arrive more frequently near the opening or closing of the stock market. To capture this 'U' shape intraday pattern, we model the parameters π ± t k+1 and π t k+1 (1, 1) defined in Eqs.

Demands Function.
For each 1-second subinterval within a day used to estimate the parameters of the model, we first compute the actual demand at each price level. Suppose the HFM places ask LOs at price level P l at time t k . At time t i ∈ [t k , t k+1 ), we observe a buy MO i with volume During a typical trading day, sell and buy MOs arrive more frequently when the time is closer to the opening or closing of the market. We model π ± t k+1 and π t k+1 (1, 1) as quadratic deterministic functions of time.
during the interval [t k , t k+1 ), and use i (V M O i − V LO i ) ∨ 0 to quantify the actual demand at price level P l during [t k , t k+1 ). The computation on the bid side is symmetric (see the piecewise constant graph in Fig. 9 for an example of the actual demand during a 1-second subinterval). Then we conduct a weighted linear regression on each side of the book, with the actual demand being the response variable and the price level (specifically, its distance to S t k ) being the predictor, to estimate Q ± t k+1 . We place higher weight on price levels closer to S t k and smaller weights on the price levels which are deep in the book. Fig. 9 shows the prototypical linear fit to the actual demand function in one subinterval. Fig. 10 plots the estimated time series (c ± t k , p ± t k ) throughout a trading day. By virtue of the augmented Dickey-Fuller test (ADF), all (c ± . , p ± . )-related time series defined in Eq. (8) are reasonably stationary.
We then proceed to estimate the i-day conditional expectations µ ±,i {c,p} defined in Eq. (8) by averaging the corresponding regression parameters over all subintervals within that day. We denote these estimates byμ ±,i {c,p} . Table 1 shows the average ofμ ±,i {c,p} over all 252 trading days in 2019. These results suggest that the symmetry assumption imposed on the demand of buy and sell orders (Eq. (29)), and the assumption of independence between c ± and p ± (Eq. (29)) are largely satisfied.
In our implementation, the estimates of µ ± {c,p} used to compute the optimal strategies in the i-th trading day are obtained by averagingμ ±,i−j {c,p} (j = 1, . . . , 20) over the previous 20 training days. Drift of the Midprice Process. Following standard conventions in the literature, we set the fundamental price S t k to be the midprice, i.e., the average of the best bid and best ask prices (see also Hendershott & Menkveld (2014)). Recall, from Section 3.2, the definition ∆ where S t k is the midprice at time t k . Since the optimal strategies are computed using a backward induction algorithm, we need to estimate ∆ t k , and additionally make predictions on future price changes conditioned on the present information (see Eq. (25)). For computational efficiency (see μ + c = 94.86μ − c = 98.801 µ + p = 3.977μ − p = 3.981 µ + cp = 432.06μ − cp = 451.53 µ + c 2 = 6.74 × 10 4μ− c 2 = 3.94 × 10 4 µ + p 2 = 17.25μ − p 2 = 17.30 µ + c 2 p = 3.22 × 10 5μ− c 2 p = 1.90 × 10 5 µ + c 2 p 2 = 1.73 × 10 6μ− c 2 p 2 = 1.08 × 10 5 Under this assumption, Eq. (25) simplifies as where L ±, * t k are the optimal spreads defined in Proposition 1. The above expression indicates that we only need to predict the immediate midprice change to compute the optimal strategy. In our implementation with real data, we estimate ∆ t k by taking the average over the last 5 increments in the midprice:∆ In this way, the optimal strategy with ∆ t k is able to respond quicker to local midprice trends.
Remark 4 In practice, one could expect ∆ t k t j = E(S t j+1 − S t j |F t k ) to quickly decrease to 0 as j is farther away from k, otherwise, statistical arbitrage opportunities would appear. Furthermore, the estimation error of the forecasts ∆ t k t j increases quickly as t j is farther away from t k . Hence, the reduction in the misspecification error (the error in assuming that ∆ t k t j = 0 when they are not) will be offset by the estimation error of the forecasts ∆ t k t j . Therefore, in practice, it is better to consider very few steps ahead forecasts in formula (25). The assumption (41) appears to be a good compromise between accuracy and computational efficiency.

Results
This section shows the performance of optimal strategies on the MSFT stock during the year 2019.
We compute the terminal cash flow W T and inventory I T for each trading day by executing the optimal strategy over a time period against the observed market data. Within each subinterval [t k , t k+1 ), the change in inventory is given by are the actual numbers of filled shares in the HFM's placement on ask and bid side, respectively, and computed from transaction data (in the same way as we compute the actual demand described in Section 5.1). The change in cash flows are given by are, respectively, the ask and bid prices implied by the strategy. As a comparison benchmark, we also consider fixed-level strategies, which always quote at some fixed level in the LOB (e.g., always quote at level I, level II, etc...).
Control on Terminal Inventory. Fig. 11 shows the intraday price and inventory paths of the optimal strategy compared with the 'Level 1'-'Level 6' strategies for a prototypical trading day.
As we can see from Fig. 11a, the optimal prices typically swing between the levels 2 and 3 in the LOB at the beginning of the trading period. During the last portion of the trading horizon, the optimal ask prices go down from level 3 to level 2, and the optimal bid prices go down from level 3 to level 6. This is the case because, as the HFM gains a positive net position during the trading process (see Fig. 11b), she gradually lowers both her ask and bid prices to buy less and sell more and, hence, to revert the net position towards zero. As shown in Fig     HFM will get when liquidating her inventory I T with MOs based on the state of the book at time T . We refer toS T I T as the liquidation proceeds. We do not observe significant differences with the results presented in Table 2. This suggests that the penalty parameter λ, fixed to be 0.0005, guarantees that the term (S T − λI T )I T in the objective function matches well the realized average proceeds of liquidating all net positions using MOs at end of the trading horizon.
Based on the results of Table 2 and Table 3, we can conclude that the optimal strategies outperform the fixed level 1-level 6 strategies. With the incorporation of the drift term ∆ t k in the midprice process, we achieve a higher average and a lower standard deviation of the terminal values. We observe that allowing for simultaneous arrivals of buy and sell MOs also leads to a higher average of the terminal values. Hereafter we focus on the optimal strategy computed using non-martingale fundamental price dynamics and assuming π t k (1, 1) ≥ 0. The optimal strategy yields a positive average terminal value. However, as shown in Fig. 12, the distributions of terminal values appear to exhibit heavy tails on both sides with kurtosis larger than 14. Such a large kurtosis results in high standard deviation estimates. We use the subsample bootstrap method proposed by Hall & LePage (1996) to construct a confidence interval for the mean. From Fig. 12a, we can see that the 95%-confidence interval for the mean of the terminal objective W T + S T I T − λI 2 T is [−1.09 × 10 5 , 2.32 × 10 5 ]. Fig. 12b shows that the 95%-confidence interval for the mean of the terminal values W T +S T I T is [−1.11 × 10 5 , 2.31 × 10 5 ]. We remark, however, that bootstrap based CIs tend to be highly conservative for heavy tailed distributions as shown in the simulations of Peng (2004). In Section 5.3, we will show that these extreme negative revenues are due to large structural breaks over time, and discuss how to identify and potentially exclude atypical days from the analysis.

Days with Extreme Negative Revenues
On some days, the market experiences 'atypical' demand and supply due to various factors (e.g. non-scheduled news arrival, entry of new market participants, etc.), which are not predictable from recent market data. These 'atypical' patterns can result in structural parameter breaks, and constitute the main reason for the observance of extreme negative revenues in Section 5.2. In our case, this means that the parameter values estimated based on the last 20 days can differ by a large extent from the actual parameter values of the current trading day when the strategy is implemented.
One key parameter that significantly affects the performance of the optimal strategies is µ ± cp , defined in Eq. (8). Recall the value of c ± p ± is the y-intercept of the demand functions (see Fig. 1) and a biased estimate of µ ± cp can lead to misleading predictions of filled shares near the midprice, which are the most critical ticks. For each trading day i, we therefore compute the difference between the average of historical estimated values of µ ± cp based on 20 past days and the estimated values from the current trading day i: whereμ ±,i cp is defined in Section 5.1. The empirical distributions of err ±,i cp are heavy right-tailed which means that µ ± cp are much overestimated for some trading days. We therefore identify days when either µ + cp or µ − cp are overestimated, and mark days with error larger than the 0.95 quantile of the empirical distributions of err ±,i cp as days with large structural parameter break.   Table 4: Terminal objective value W T + S T I T − λI 2 T . We consider both the inclusion and exclusion of the 22 'Atypical' Days. We set λ = 0.0005.
Another critical parameter in our analysis is the value of π t k (1, 1), which represents the probability of simultaneous arrival of buy and sell MOs within a 1-second subinterval. To determine whether a structural break has occurred in the estimate of such a parameter on a given trading day i, we first compute the historical estimate of π t k (1, 1) for the day i as: where {π i t k+1 (1, 1)} k=0,...,N are the least-squares estimates ofπ i t k+1 (1, 1) defined in (40). We then compute the difference between the historical estimatesπ i (1, 1) and the estimated probabilitỹ (1 +,i t k+1 · 1 −,i t k+1 )/N for day i, and set err i π(1,1) :=π i (1, 1) −π i (1, 1). We mark days for which the absolute value of err i π(1,1) is greater than the 0.95 quantile of its empirical distribution as days with large structural parameter breaks.
Results after Excluding Days with Large Structural Parameter Break. Using the criteria described above, we identify days with a large structural break in the estimate of either µ ± cp or π t k (1, 1). Our analysis indicates that there are 22 out of 232 trading days for which this occurs. of terminal values are also significantly increased and reduced, respectively. As shown in the histograms of Fig. 13, the selection criterion discussed above effectively excludes days where revenues are extreme and negative.
7 The confidence intervals are constructed using the standard normal approximation method and the subsample bootstrap method proposed by Hall & LePage (1996), as mentioned in Section 5.2. Peng (2004) show that the subsample bootstrap method provides a more conservative estimate for the confidence interval of the mean if the distribution is heavy-tailed.   The above identities will be proved below in Step 4. Using the previous arguments, we can compute the conditional expectation E · F t k of the terms in Eqs. (A-4)-(A-7), and plug them in the righthand side of Eq. (A-3) to get: Step 2. We next prove that L ±, * t k are indeed the maximum point of the functionf (L + t k , L − t k ). To this end, we will use Lemma 1, which states that α t k < 0. Indeed, for every t k , we have: for some deterministic constant d k and Note also that h t k defined in Eq. (20) can also be written as where d k , ξ k are the same as those in (A-17). Since h t N +1 = 0 and h t N +1 = 0, for the time point t N , we have that h t N = d N + ξ N ∆ t N and h t N = d N . By induction, we get where k−1 =k ξ := 1, and -19) In particular, we have Plugging the above expression into (2) A ± t k defined in (A-12) and, then, plugging (1) A ± t k , (2) A ± t k , and (3) A ± t k into (A-11), we deduce that (A-20) This proves Proposition 1 and Theorem 2 at once.

A.3 Proof of Theorem 1 (Verification Theorem)
Throughout, W t i , I t i , for i = k, . . . , N + 1, are the cash holding and inventory processes resulting from adopting an admissible placement strategy L ± t i , i = k, . . . , N . In contrast, for i = k + 1, . . . , N + 1, W * t i , I * t i and W t i , I t i are respectively the resulting cash holding and inventory processes starting from initial states W t k , I t k , when setting L ± t i = L ±, * t i and L ± t i = L ± t i , for some arbitrary admissible placement strategy L ± t i . First note that, for an arbitrary admissible placement strategy The last equation follows from (16) and Proposition 1. That is, α t k , h t k , g t k in v(t k , s, w, i) = w + α t k i 2 + si + h t k i + g t k are picked in order for (16) to hold true. We then have that v(t k , S t k , W t k , I t k ) ≥ sup (A-28) The first equality in Eq. (A-28) holds because v(T, S T , W T , I T ) = W T + S T I T − λI 2 T by the terminal conditions α T = −λ, g T = 0, h T = 0.
Next we prove that v(t k , S t k , W t k , I t k ) ≤ V t k . To this end, recall from Proposition 1 that we pick α t k , h t k , and g t k so that v(t i , S t i , W * for all i = k, . . . , N . Hence, by induction, v(t k , S t k , W t k , I t k ) = v(t k , S t k , W * t k , I * t k ) It also trivially follows that We then conclude that v(t k , S t k , W t k , I t k ) ≤ V t k , which combined with (A-28) implies that v(t k , S t k , W t k , I t k ) = V t k .

A.4 Proof of Proposition 2 (Conditions for Positive Spread)
We first prove the result under the martingale condition (14). By Eq. (17), we need to prove that L +, * of (3) A + the coefficients of µ + p in N ( (3) A +