To Hedge or Not to Hedge: Optimal Strategies for Stochastic Trade Flow Management Philippe Bergault, Hamza Bodor, Olivier Guéant Abstract This paper addresses the trade-off between internalisation and externalisation in the management of stochastic trade flows. We consider agents who must absorb flows and manage risk by deciding whether to warehouse it or hedge in the market, thereby incurring transaction costs and market impact. Unlike market makers, these agents cannot skew their quotes to attract offsetting flows and deter risk-increasing ones, leading to a fundamentally different problem. Within the Almgren-Chriss framework, we derive almost-closed-form solutions in the case of quadratic execution costs, while more general cases require numerical methods. In particular, we discuss the challenges posed by artificial boundary conditions when using classical grid-based numerical PDE techniques and propose reinforcement learning methods as an alternative. Key words: stochastic optimal control, internalisation vs. externalisation dilemma, central risk book, reinforcement learning. 1 Introduction Since the notable renewal of academic research topics following the 2008 financial crisis, market impact has assumed a central role in the quantitative finance literature. Over the past two decades, numerous datasets have been analysed to estimate the market impact of (i) individual limit and market orders (see for instance [ 10 ] , [ 17 ] and [ 21 ] ), and (ii) meta-orders (see for example [ 4 ] , [ 12 ] and [ 40 ] ). Beyond empirical and phenomenological studies documenting the so-called square-root law(s) of market impact and other stylised facts, microfoundations and theoretical justifications have been proposed to enhance our understanding of the microscopic dynamics of prices and limit order books (see for instance [ 9 ] , [ 11 ] and [ 20 ] ) and delineate the types of models suitable for practical applications (see [ 26 ] for early discussions on the topic, particularly the necessary linearity of permanent market impact). Overall, a variety of market impact models have been proposed: highly realistic models with nonlinear and / or non-Markovian transient dynamics have been developed and applied to specific problems, while simpler models, mainly inspired by the Almgren-Chriss [ 2 , 5 ] and Obizhaeva-Wang [ 44 ] frameworks, have been utilised to ensure the tractability of equations within otherwise complex models. Market impact models have indeed served as foundational components in the development of optimal execution strategies, proving useful for brokers optimising their arrival price / implementation shortfall or VWAP algorithms (e.g. [ 1 ] , [ 2 ] , [ 5 ] , [ 15 ] , [ 24 ] , [ 30 ] , [ 31 ] and [ 44 ] ), as well as for algorithmic traders aiming to exploit alpha signals without excessively impacting the market (see for instance [ 23 ] , [ 32 ] , [ 33 ] and [ 37 ] ). Moreover, they have demonstrated their value to help designing strategies to better hedge large positions in derivatives or contingent claims written on assets with high execution costs (see [ 3 ] , [ 28 ] and [ 47 ] ). More recently, market impact models have been used to develop frameworks addressing the financial trade-off between internalising and externalising trading flows (see [ 6 ] , [ 7 ] , [ 8 ] – see also [ 13 ] and [ 14 ] for related discussions). 1 1 1 Pre-hedging is a related topic on which a few papers have recently been written, see for instance [ 41 ] . In a nutshell, given a stochastic flow of buy and sell trades received in a book, to what extent is it optimal to keep the risk in the book and wait for offsetting flows, rather than hedging the risk directly on the market, thereby incurring transaction costs and price impact? This issue is, of course, faced by market makers and dealers whose activity – across all OTC markets – involves quoting buy and sell prices to their clients and using their balance sheet to warehouse the risk until an opposite order arrives, or until they decide to utilise their outside option of actively trading with other dealers on the inter-dealer segment of the market (see [ 48 ] for a discussion on the two segments of the FX market). Unlike market makers, who have significant flexibility to propose skewed prices that attract or deter one side of the flow in order to rebalance their positions (or even to stop quoting a product on the bid or ask side entirely), certain participants – for example, those dealing with retail equity flows or managing central risk books – must absorb flows and manage the associated risk appropriately. Their choices lie in deciding whether to continue bearing the risk or, alternatively, to offload it on markets while optimising the trading speed to mitigate execution costs. Although practices have evolved with the advent of competition between trading platforms associated with MiFID and Reg. NMS, which has encouraged various participants to establish dark pools and crossing networks to offer parts of their inventories to other participants while limiting market impact, there exists, to our knowledge, only one model, presented in [ 43 ] , addressing the trade-off between internalisation and externalisation beyond the case of market makers. The authors of [ 43 ] , motivated by the development of central risk books in many banks, developed a model where the flow of trades is stochastic and can follow Brownian, positively autocorrelated, or mean-reverting dynamics. Their model is, in fact, an extension of optimal execution models à la Obizhaeva-Wang with no risk aversion, where the inventory is not fixed but rather stochastic. In particular, they model transient price impact using a linear push factor and resilience at an exponential rate. Additionally, they consider execution costs, but in quadratic form only. Because of their specific choice of transient market impact and quadratic execution costs, the model reduces to a linear-quadratic (LQ) optimal control problem that can be solved in closed form using the solution of a Riccati differential equation. The aim of this article is to propose different models for optimising the management of a stochastic trade flow in the risk-averse case, using the Almgren-Chriss framework for execution costs and market impact. More precisely, we consider a risk-averse trader whose objective is either to maximise the expected CARA utility or a risk-adjusted expectation ( à la Cartea-Jaimungal; see [ 15 ] ) of their profit at a terminal time T . We show that, in both cases, the problem with quadratic execution costs can be tackled almost explicitly, as it reduces to solving a matrix Riccati differential equation. However, for other forms of execution costs, the problem becomes more challenging due to the uncontrolled nature of trade flows, which results in Hamilton-Jacobi(-Bellman) equations that cannot be solved in closed form and may be difficult to approximate numerically because of their sensitivity to artificially-imposed boundary conditions (except in the limiting case of linear bid-ask spread costs). In Section 2, we present the models and the associated partial differential equations. In Section 3, we show that these equations can be solved in closed form in the case of quadratic execution costs, up to solving a matrix Riccati differential equation. In Section 4, we address numerical resolution. In particular, we demonstrate how the limiting case of linear execution costs can be tackled using classical techniques, while arguing that reinforcement learning techniques are viable alternatives to classical grid-based numerical PDE techniques for addressing more general cases. 2 Internalisation vs. Externalisation in the Almgren-Chriss Model 2.1 Mathematical Framework 2.1.1 State Variables We focus on a single asset and a trader managing a book that receives stochastic trade flows over the time interval [0,T] , where T>0 . Throughout this paper, we consider a filtered probability space \left(\Omega,\mathcal{F},\mathbb{P};\mathbb{F}=(\mathcal{F}_{t})_{t\in[0,T]}\right) satisfying the usual conditions. This probability space is assumed to be sufficiently large to support all the processes introduced. By default, all processes are adapted to the above filtration. Assuming Brownian dynamics for the trade flows, 2 2 2 This framework can be generalised to include trade flows with positive or negative autocorrelation, as in [ 43 ] . and absolutely continuous trading strategies, the inventory process (q_{t})_{t\in[0,T]} evolves as: \displaystyle dq_{t}=v_{t}dt+\nu dB_{t}, (1) where q_{0}\in\mathbb{R} and \nu\in\mathbb{R}_{+} are given, (v_{t})_{t\in[0,T]} represents the trading velocity of the trader, and (B_{t})_{t\in[0,T]} is a standard Brownian motion. The asset price process (S_{t})_{t\in[0,T]} is modelled as a Brownian motion impacted by the trader’s strategy: \displaystyle dS_{t}=kv_{t}dt+\sigma dW_{t}, (2) where S_{0}\in\mathbb{R} is given, \sigma\in\mathbb{R}^{*}_{+} is the volatility parameter, k\in\mathbb{R}_{+} represents the permanent market impact parameter, and (W_{t})_{t\in[0,T]} is a standard Brownian motion. We assume that, together, (B_{t})_{t\in[0,T]} and (W_{t})_{t\in[0,T]} form a two-dimensional Brownian motion with a quadratic covariation coefficient \rho\in[-1,1] . The trader’s cash account (X_{t})_{t\in[0,T]} evolves according to: \displaystyle dX_{t}=-v_{t}S_{t}dt-L(v_{t})dt, (3) where X_{0}\in\mathbb{R} is given, and L:\mathbb{R}\rightarrow\mathbb{R}_{+} represents the instantaneous market impact and/or execution costs incurred. In this paper, we primarily focus on cases where L is a strictly convex and asymptotically super-linear function, such as L(v)=\frac{\psi}{2}|v|+\eta v^{1+\phi} , with \psi\in\mathbb{R}_{+} , \eta\in\mathbb{R}^{*}_{+} , and \phi\in\mathbb{R}^{*}_{+} . The limiting case \eta\to 0 will also be discussed. 2.1.2 Objective Functions We consider two optimisation problems. In the first, the trader aims to maximise the expected CARA utility of their profit at terminal time T : \text{PnL}_{T}:=X_{T}+q_{T}S_{T}-\frac{k}{2}q_{T}^{2}-\ell(q_{T}), where \frac{k}{2}q_{T}^{2} accounts for the cost of liquidation associated with permanent market impact (as in à la Almgren-Chriss models), and \ell(q_{T}) represents additional execution costs at time T (see [ 29 ] ). The corresponding optimisation problem is: \displaystyle\sup_{v\in\mathcal{A}_{A}}\mathbb{E}\left[-\exp\left(-\gamma\left(X_{T}+q_{T}S_{T}-\frac{k}{2}q_{T}^{2}-\ell(q_{T})\right)\right)\right], (Model A) where \gamma denotes the absolute risk aversion parameter of the trader and where \mathcal{A}_{A} is the set of admissible controls that consists in adapted processes with additional integrability constraints. Using Eqs. ( 1 ) and ( 2 ), and applying Itô’s formula, the PnL at time T can be expressed as: \text{PnL}_{T}=X_{0}+q_{0}S_{0}+\int_{0}^{T}\left(-L(v_{t})+kv_{t}q_{t}+\rho\nu\sigma\right)dt+\int_{0}^{T}\nu S_{t}dB_{t}+\int_{0}^{T}\sigma q_{t}dW_{t}-\frac{k}{2}q_{T}^{2}-\ell(q_{T}). To approximate the variance of the PnL, we can follow à la Cartea-Jaimungal models and consider only the variance of the stochastic integrals: \mathbb{V}\left(\int_{0}^{T}\nu S_{t}dB_{t}+\int_{0}^{T}\sigma q_{t}dW_{t}\right)=\int_{0}^{T}\left(\nu^{2}S_{t}^{2}+\sigma^{2}q_{t}^{2}+2\rho\nu\sigma q_{t}S_{t}\right)dt. The second optimisation problem we consider, a mean-variance-like formulation, is subsequently: \displaystyle\sup_{v\in\mathcal{A}_{B}}\mathbb{E}\left[\int_{0}^{T}\left(-L(v_{t})+kv_{t}q_{t}+\rho\nu\sigma-\frac{\gamma}{2}\left(\sigma^{2}q_{t}^{2}+\nu^{2}S_{t}^{2}+2\rho\sigma\nu q_{t}S_{t}\right)\right)dt-\frac{k}{2}q_{T}^{2}-\ell(q_{T})\right], (Model B) where \frac{\gamma}{2} is the constant penalising the proxy of the variance term and where \mathcal{A}_{B} is the set of admissible controls defined as \mathcal{A}_{B}=\left\{(v_{t})_{t\in[0,T]},\;\mathbb{R}\text{-valued},\;\mathbb{F}\text{-adapted}\left|\mathbb{E}\left[\int_{0}^{T}v_{t}^{2}dt\right]<+\infty\right.\right\}. 2.2 Hamilton-Jacobi-Bellman Equations and Changes of Variables 2.2.1 Model A The Hamilton-Jacobi-Bellman equation associated with Model A is: \displaystyle 0 \displaystyle= \displaystyle\partial_{t}u(t,x,q,S)+\frac{1}{2}\sigma^{2}\partial^{2}_{SS}u(t,x,q,S)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}u(t,x,q,S)+\rho\sigma\nu\partial^{2}_{qS}u(t,x,q,S) (4) \displaystyle+\ \underset{v}{\sup}\Big(v\partial_{q}u(t,x,q,S)-\big(vS+L(v)\big)\partial_{x}u(t,x,q,S)+kv\partial_{S}u(t,x,q,S)\Big), with terminal condition u(T,x,q,S)=-\exp\left(-\gamma\left(x+qS-\frac{k}{2}q^{2}-\ell(q)\right)\right) . Classical results from the optimal execution literature (see [ 30 ] ) suggest to consider the ansatz u(t,x,q,S)=-\exp\left(-\gamma\left(x+qS-\frac{k}{2}q^{2}+\theta(t,q,S)\right)\right). We then easily see that to obtain a solution to Eq. ( 4 ), it is sufficient to obtain a solution to \displaystyle 0 \displaystyle= \displaystyle\!\!\!\!\partial_{t}\theta(t,q,S)+\frac{1}{2}\sigma^{2}\partial^{2}_{SS}\theta(t,q,S)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}\theta(t,q,S)+\rho\sigma\nu\partial^{2}_{qS}\theta(t,q,S) (5) \displaystyle\!\!\!\!-\ \frac{\gamma}{2}\sigma^{2}(q+\partial_{S}\theta(t,q,S))^{2}-\frac{\gamma}{2}\nu^{2}(S-kq+\partial_{q}\theta(t,q,S))^{2}-\gamma\rho\sigma\nu(S-kq+\partial_{q}\theta(t,q,S))(q+\partial_{S}\theta(t,q,S)) \displaystyle\!\!\!\!-\ \frac{1}{2}\nu^{2}k+\rho\sigma\nu+H\left(\partial_{q}\theta(t,q,S)+k\partial_{S}\theta(t,q,S)\right), where H(p)=\sup_{v}vp-L(v) , and the associated terminal condition is \theta(T,q,S)=-\ell(q) . In particular, the candidate optimal control writes v_{t}^{*}=H^{\prime}(\partial_{q}\theta(t,q_{t},S_{t})+k\partial_{S}\theta(t,q_{t},S_{t})). 2.2.2 Model B The Hamilton-Jacobi-Bellman equation associated with Model B is: \displaystyle 0 \displaystyle= \displaystyle\partial_{t}u(t,q,S)+\frac{1}{2}\sigma^{2}\partial^{2}_{SS}u(t,q,S)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}u(t,q,S)+\rho\sigma\nu\partial^{2}_{qS}u(t,q,S) (6) \displaystyle-\ \frac{\gamma}{2}\sigma^{2}q^{2}-\frac{\gamma}{2}\nu^{2}S^{2}-\gamma\rho\nu\sigma qS \displaystyle+\ \rho\sigma\nu+\underset{v}{\sup}\Big(v\partial_{q}u(t,q,S)-L(v)+kvq+kv\partial_{S}u(t,q,S)\Big), with terminal condition u(T,q,S)=-\frac{k}{2}q^{2}-\ell(q) . Here, we use the change of variables u(t,q,S)=-\frac{k}{2}q^{2}+\theta(t,q,S) and we easily see that to obtain a solution to Eq. ( 6 ), it is sufficient to obtain a solution to \displaystyle 0 \displaystyle= \displaystyle\partial_{t}\theta(t,q,S)+\frac{1}{2}\sigma^{2}\partial^{2}_{SS}\theta(t,q,S)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}\theta(t,q,S)+\rho\sigma\nu\partial^{2}_{qS}\theta(t,q,S) (7) \displaystyle-\ \frac{\gamma}{2}\sigma^{2}q^{2}-\frac{\gamma}{2}\nu^{2}S^{2}-\gamma\rho\nu\sigma qS \displaystyle-\ \frac{1}{2}\nu^{2}k+\rho\sigma\nu+H\left(\partial_{q}\theta(t,q,S)+k\partial_{S}\theta(t,q,S)\right), and the associated terminal condition is \theta(T,q,S)=-\ell(q) . In particular, the candidate optimal control writes v_{t}^{*}=H^{\prime}(\partial_{q}\theta(t,q_{t},S_{t})+k\partial_{S}\theta(t,q_{t},S_{t})). 3 The Quadratic Execution Cost Case To address the internalisation vs. externalisation trade-off, we consider in this section the benchmark case corresponding to quadratic execution costs, 3 3 3 The case of quadratic costs can easily be generalized to a portfolio of correlated assets. i.e., L(v)=\eta v^{2} and \ell(q)=Kq^{2} , where \eta\in\mathbb{R}_{+}^{*} and K\in\mathbb{R}_{+} . In this case, the solutions of both Eqs. ( 5 ) and ( 7 ) are (up to a time-dependent additive constant) time-dependent quadratic forms in the variable \begin{pmatrix}q\\ S\end{pmatrix} . Furthermore, the matrices of these quadratic forms satisfy matrix Riccati differential equations and can therefore be efficiently computed numerically. Let us start with Model A and the following result, whose proof follows from straightforward computation: Proposition 1 . Let \Sigma=\begin{pmatrix}\sigma^{2}&\rho\sigma\nu\\ \rho\sigma\nu&\nu^{2}\end{pmatrix} and J=\begin{pmatrix}0&1\\ 1&0\end{pmatrix} . Let U=\frac{1}{\eta}\begin{pmatrix}1&k\\ k&k^{2}\end{pmatrix}-2\gamma J\Sigma J,\ Y=\gamma J\Sigma\begin{pmatrix}1&0\\ -k&1\end{pmatrix}\ \text{and}\ Q=-\frac{\gamma}{2}\begin{pmatrix}1&0\\ -k&1\end{pmatrix}^{\intercal}\Sigma\begin{pmatrix}1&0\\ -k&1\end{pmatrix}. Let A\in C^{1}([0,T],S_{2}(\mathbb{R})) be a solution of the matrix Riccati differential equation A^{\prime}(t)=A(t)UA(t)+A(t)Y+Y^{\intercal}A(t)+Q with the terminal condition A(T)=\begin{pmatrix}K&0\\ 0&0\end{pmatrix}. Then, \theta(t,q,S)=-\begin{pmatrix}q\\ S\end{pmatrix}^{\intercal}A(t)\begin{pmatrix}q\\ S\end{pmatrix}+\int_{t}^{T}\text{Tr}(J\Sigma JA(s))ds+\left(\frac{1}{2}\nu^{2}k-\rho\sigma\nu\right)(T-t) defines a solution to Eq. ( 5 ) and satisfies the terminal condition \theta(T,q,S)=-Kq^{2} . Remark 1 . Local existence (and uniqueness) of a solution to the above Riccati equation for A is trivial. However, global existence on [0,T] is not and we have no guarantee of no blow up in finite time for Model A. For this reason, we concentrate in what follows on Model B. Remark 2 . In Model A, using the notations of the above proposition, the candidate optimal control writes v_{t}^{*}=-\frac{1}{\eta}\begin{pmatrix}1\\ k\end{pmatrix}^{\intercal}A(t)\begin{pmatrix}q_{t}\\ S_{t}\end{pmatrix} For Model B we have a simpler result, whose proof also follows from straightforward computation: Proposition 2 . Let \Sigma=\begin{pmatrix}\sigma^{2}&\rho\sigma\nu\\ \rho\sigma\nu&\nu^{2}\end{pmatrix} and J=\begin{pmatrix}0&1\\ 1&0\end{pmatrix} . Let A\in C^{1}([0,T],S_{2}(\mathbb{R})) be a solution of the matrix Riccati differential equation A^{\prime}(t)=\frac{1}{\eta}A(t)\begin{pmatrix}1&k\\ k&k^{2}\end{pmatrix}A(t)-\frac{\gamma}{2}\Sigma, with the terminal condition A(T)=\begin{pmatrix}K&0\\ 0&0\end{pmatrix}. Then, \theta(t,q,S)=-\begin{pmatrix}q\\ S\end{pmatrix}^{\intercal}A(t)\begin{pmatrix}q\\ S\end{pmatrix}+\int_{t}^{T}\text{Tr}(J\Sigma JA(s))ds+\left(\frac{1}{2}\nu^{2}k-\rho\sigma\nu\right)(T-t) defines a solution to Eq. ( 7 ) and satisfies the terminal condition \theta(T,q,S)=-Kq^{2} . Remark 3 . Unlike for Model A, the existence (and uniqueness) on [0,T] of a solution to the above Riccati equation for A is clear. Remark 4 . In Model B, using the notations of the above proposition, the candidate optimal control writes v_{t}^{*}=-\frac{1}{\eta}\begin{pmatrix}1\\ k\end{pmatrix}^{\intercal}A(t)\begin{pmatrix}q_{t}\\ S_{t}\end{pmatrix} 4 Beyond Quadratic Execution Costs 4.1 Introductory Remarks on Boundaries The numerical approximation of the solution of partial differential equations such as Eqs. ( 5 ) and ( 7 ) requires the introduction of artificial boundaries for both inventories and prices. To better understand the issue with the financial problem at stake, let us focus on Model B in the specific case where k=\rho=0 . In this case, the partial differential equation ( 7 ) simplifies to: \displaystyle 0 \displaystyle= \displaystyle\partial_{t}\theta(t,q,S)+\frac{1}{2}\sigma^{2}\partial^{2}_{SS}\theta(t,q,S)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}\theta(t,q,S)-\frac{\gamma}{2}\sigma^{2}q^{2}-\frac{\gamma}{2}\nu^{2}S^{2}+H\left(\partial_{q}\theta(t,q,S)\right). (8) Using the ansatz \theta(t,q,S)=\tilde{\theta}(t,q)-\alpha(t)-\beta(t)S^{2}, solving Eq. ( 7 ) boils down to solving \displaystyle 0 \displaystyle= \displaystyle\partial_{t}\tilde{\theta}(t,q)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}\tilde{\theta}(t,q)-\frac{\gamma}{2}\sigma^{2}q^{2}+H\left(\partial_{q}\tilde{\theta}(t,q)\right), (9) with the terminal condition \tilde{\theta}(T,q)=-\ell(q) , along with the system of ordinary differential equations: \displaystyle\alpha^{\prime}(t) \displaystyle=-\sigma^{2}\beta(t),\quad\alpha(T)=0, \displaystyle\beta^{\prime}(t) \displaystyle=-\frac{\gamma}{2}\nu^{2},\quad\beta(T)=0, whose solution is: \alpha(t)=\frac{\gamma}{4}\nu^{2}\sigma^{2}(T-t)^{2},\qquad\beta(t)=\frac{\gamma}{2}\nu^{2}(T-t). In the case of quadratic execution costs, and following Proposition 2, \tilde{\theta}(t,q) is, up to a time-dependent additive term independent of q , equal to -a(t)q^{2} , where: a^{\prime}(t)=-\frac{1}{2}\gamma\sigma^{2}+\frac{1}{\eta}a(t)^{2},\qquad a(T)=K. Solving this equation using classical techniques leads to: a(t)=\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}\frac{1+\frac{K-\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}{K+\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}\exp\left(-2\sqrt{\frac{\gamma\sigma^{2}}{2\eta}}(T-t)\right)}{1-\frac{K-\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}{K+\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}\exp\left(-2\sqrt{\frac{\gamma\sigma^{2}}{2\eta}}(T-t)\right)}. (10) In particular, we obtain: v^{*}_{t}=-\sqrt{\frac{\gamma\sigma^{2}}{2\eta}}\frac{1+\frac{K-\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}{K+\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}\exp\left(-2\sqrt{\frac{\gamma\sigma^{2}}{2\eta}}(T-t)\right)}{1-\frac{K-\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}{K+\sqrt{\frac{\gamma\sigma^{2}\eta}{2}}}\exp\left(-2\sqrt{\frac{\gamma\sigma^{2}}{2\eta}}(T-t)\right)}q_{t}. (11) This result indicates that the trader trades continuously in proportion to their current inventory – the proportionality coefficient being time-dependent but independent of \nu , as in the standard Almgren-Chriss case with constant (non-random) inventories. To numerically approximate the solution to Eq. ( 9 ) beyond quadratic execution costs, one must artificially impose inventory boundaries at, say, \pm Q , where Q\in\mathbb{R}_{+}^{*} is large, and choose boundary conditions for \tilde{\theta}(t,\cdot) at \pm Q . In general, selecting the correct boundary condition is impossible (think of dealing with the quadratic case without knowing the closed-form expression) and the error propagates inside the domain. However, there is a limiting case corresponding to linear bid-ask spread costs, i.e., L(v)=\frac{\psi}{2}|v| and \ell(q)=\frac{\psi}{2}|q| , for which boundary conditions are natural. In the limiting case of linear execution costs, the problem must in fact be formulated differently: instead of trading continuously, the trader selects a sequence of stopping times 0\leq\tau_{1}\leq\ldots\leq\tau_{i}\leq\ldots and corresponding random variables \xi_{1},\ldots,\xi_{i},\ldots where \xi_{i} represents the quantity traded at time \tau_{i} . The inventory process is then q_{t}=q_{0}+\nu B_{t}+\sum_{\tau_{i}\leq t}\xi_{i}, the price follows S_{t}=S_{0}+\sigma W_{t}, and the trader’s cash account evolves as X_{t}=X_{0}-\sum_{\tau_{i}\leq t}\xi_{i}S_{\tau_{i}}-\frac{\psi}{2}\sum_{\tau_{i}\leq t}|\xi_{i}|. At terminal time T , the trader’s PnL is: \text{PnL}_{T}=X_{T}+q_{T}S_{T}-\frac{\psi}{2}|q_{T}|=X_{0}+q_{0}S_{0}+\int_{0}^{T}\sigma q_{t-}dW_{t}+\int_{0}^{T}\nu S_{t}dB_{t}-\frac{\psi}{2}\sum_{\tau_{i}\leq t}|\xi_{i}|-\frac{\psi}{2}|q_{T}|. The limiting case of Model B corresponds therefore to maximising: \mathbb{E}\left[-\frac{\psi}{2}\sum_{\tau_{i}\leq T}|\xi_{i}|-\frac{\psi}{2}|q_{T}|-\frac{\gamma}{2}\int_{0}^{T}\sigma^{2}q_{t-}^{2}dt-\frac{\gamma}{2}\int_{0}^{T}\nu^{2}S_{t}^{2}dt\right] over the set of stopping times and admissible trade sizes. This is an impulse control problem, leading to the following quasi-variational inequality (QVI): 0=\max\begin{cases}\partial_{t}\theta(t,q,S)+\frac{1}{2}\sigma^{2}\partial^{2}_{SS}\theta(t,q,S)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}\theta(t,q,S)-\frac{\gamma}{2}\sigma^{2}q^{2}-\frac{\gamma}{2}\nu^{2}S^{2},\\ \underset{\xi}{\max}\,\theta(t,q+\xi)-\theta(t,q)-\frac{\psi}{2}|\xi|\end{cases} with terminal condition \theta(T,q)=-\frac{\psi}{2}|q| . Using the same ansatz as for Eq. ( 8 ), this equation reduces to 0=\max\begin{cases}\partial_{t}\tilde{\theta}(t,q)+\frac{1}{2}\nu^{2}\partial^{2}_{qq}\tilde{\theta}(t,q)-\frac{\gamma}{2}\sigma^{2}q^{2},\\ \underset{\xi}{\max}\,\tilde{\theta}(t,q+\xi)-\tilde{\theta}(t,q)-\frac{\psi}{2}|\xi|\end{cases} with terminal condition \tilde{\theta}(T,q)=-\frac{\psi}{2}|q| . The optimal strategy is deduced from the above QVI through the maximiser \xi . The QVI has no closed-form solution but can be solved numerically using a grid-based scheme, assuming that Q is chosen sufficiently large such that any trade bringing |q| close to Q is automatically hedged in the market at a cost per asset equal to \psi/2 . In other words, in the case of linear execution costs, if Q is sufficiently large, the boundary condition should be given by \partial_{q}\tilde{\theta}(t,\pm Q)=\mp\frac{\psi}{2} . Of course this reasoning cannot generalize to strictly convex execution costs and errors from the boundaries will propagate inside the domain when approximating the solution of PDEs. 4.2 Policy Learning via Reinforcement Learning Reinforcement Learning (RL) is a machine learning paradigm in which an agent optimizes a policy through interactions with an environment and feedbacks in the form of rewards. Unlike supervised learning, which relies on labeled data, RL employs trial and error to maximize cumulative rewards. Over the years, RL has demonstrated remarkable success across various domains, including robotics, game playing, and, more recently, finance [ 30 , 36 ] . In finance, RL has gained significant attention for its ability to tackle dynamic and stochastic decision-making problems. Its adaptability allows it to learn nearly-optimal strategies without requiring explicit assumptions about market dynamics, making it particularly valuable in complex environments. RL has been applied to portfolio optimization, market making, high-frequency trading, and optimal execution, where it enables adaptive decision-making that responds to evolving market conditions, even in high dimensions [ 19 , 45 ] . For a comprehensive review of RL techniques in financial applications, we refer readers to [ 22 ] . A key area of application is portfolio management, where RL optimizes asset allocation based on market fluctuations [ 27 , 35 , 39 , 53 , 55 ] . In market making, RL assists in setting bid and ask quotes and managing inventory risk efficiently [ 16 , 25 , 51 , 52 ] . Similarly, in optimal execution, RL helps minimizing execution costs and market impact in dynamic trading environments while, sometimes, minimizing risk [ 18 , 38 , 42 , 54 ] . The traditional way to handle the aforementioned financial problems relies on stochastic optimal control methods, such as Hamilton-Jacobi-Bellman equations and the associated grid-based numerical approximation methods. While these methods are widely used and often lead to very good results, they often require to bound the state space and to artificially impose boundary conditions. Unlike HJB-based approaches, RL is simulation-based and learns directly from the environment’s dynamics, eliminating the need for artificial boundary conditions. This flexibility allows RL to adapt naturally to the properties of the considered environment, making it particularly suitable for settings where specifying relevant artificial boundary conditions is difficult or impractical. In the following sections, we examine how reinforcement learning can be used to manage stochastic order flow while minimizing execution costs and mitigating inventory risk. In particular, we compare the performance of RL-based policies with those obtained from HJB-based numerical methods. 4.3 Numerical Results 4.3.1 Experimental Setting To evaluate different strategies for managing stochastic trade flow, derived from partial differential equations or reinforcement learning, we set up a fixed parametric market environment. Unless specified otherwise, inventory is measured in lots of 5000 shares. 4 4 4 This scaling primarily enhances numerical stability in reinforcement learning by normalizing inventory values. Environment parameters: • Trading horizon: T=1\;\text{day} • Discrete time step: \Delta t=\frac{1}{100}\;\text{day} • Initial lot price: S_{0}=500,000\;\$\cdot\text{lot}^{-1} • Arithmetic volatility: \sigma=10,000\;\$\cdot\text{lot}^{-1}\cdot\text{day}^{-1/2} • Trade flow standard deviation: \nu=10\;\text{lot}\cdot\text{day}^{-1/2} • Bid-ask spread: \psi=250\;\$\cdot\text{lot}^{-1} • Running speed penalty: \eta=5\;\$\cdot\text{lot}^{-2}\cdot\text{day} • Execution cost exponent: \phi=1~(L(v)=\frac{\psi}{2}|v|+\eta v^{2}) • Risk aversion parameter: \gamma=2\cdot 10^{-6}\;\$^{-1} • Terminal inventory penalty: K=500\;\$\cdot\text{lot}^{-2} These parameters characterize the environment we use to define the market dynamics, the evolution of the inventory, and the objective function. In this section on numerical results, we focus on Model B. The objective function in this model balances expected costs with price fluctuations and inventory risk. It also discourages excessively aggressive trading and incentivizes almost complete inventory unwinding by the end of the time interval. In order to approximate the solution of the HJB equation ( 6 ) on [0,T]\times[-40,40] , we use a monotone implicit Euler scheme on a grid of size 161 for the inventory, with Neumann conditions at the boundaries corresponding to the bid-ask spread costs, i.e. \partial_{q}\tilde{\theta}(t,\pm 40)=\mp\frac{\psi}{2} . Our reinforcement learning framework is built upon mbt-gym [ 34 ] and employs Proximal Policy Optimization (PPO) [ 50 ] with training over 100 million steps. PPO is a policy gradient method that optimizes a neural network policy by alternating between sampling data through interactions with the environment and optimizing a surrogate objective function using stochastic gradient ascent. The approach includes a clip parameter that restricts policy updates to a trust region, preventing excessive policy changes that could lead to performance collapse. In our experiments, we adopt the PPO implementation from Stable Baselines3 [ 46 ] . We use a two-hidden-layer architecture (256 units per layer) with SiLU 5 5 5 SiLU (Sigmoid Linear Unit) or Swish function: f(x)=x\cdot\sigma(x) , where \sigma(x)=\frac{1}{1+e^{-x}} is the sigmoid function. activations for both the policy and value function networks. More details on the hyperparameters used for the PPO model are provided in Table 1 . Parameter Name Definition Value policy_kwargs Neural network architecture specifications pi=[256, 256] vf=[256, 256] activation_fn=SiLU learning_rate Learning rate for the optimizer 0.001 gamma (RL) Discount factor for future rewards 0.99 ent_coef Entropy coefficient for exploration 0.01 vf_coef Value function coefficient 0.5 max_grad_norm Maximum value for gradient clipping 1.0 batch_size Number of samples in each optimization batch 4000 Table 1: PPO hyperparameters used in the experiments. Because the problem involves a time interval [0,T] , we implemented a progressive training approach. This approach initially trains the model on environments with states close to the terminal time and gradually extends the time horizon until covering the complete episode (from t=0 to t=T ). Figure 1 illustrates the performance difference between two training approaches: (1) training directly on complete episodes (non-progressive) and (2) using the progressive training method. In the progressive approach, the model is trained sequentially on environments with initial times t_{0}\in[0.9,0.7,0.5,0.3,0.1] , allocating 10 million steps for each interval, followed by 50 million steps on complete episodes ( t_{0}=0 ). It shows how the non-progressive approach may quickly converge to a sub-optimal solution, mainly due to the underexploration of some states. In fact, Figure 2 presents the state space exploration patterns of both approaches. The progressive learning method exhibits more efficient exploration, concentrating on strategically important state regions (specifically, inventory levels between -35 and 35 lots). In contrast, the non-progressive approach shows suboptimal exploration patterns, particularly evident in states near t=1 . Figure 1: Comparison of training approaches showing the average episode reward curves during the training of RL agents using the progressive learning method (solid line) and the non-progressive method (dashed line). Figure 2: Heatmaps of states visited during training: non-progressive training on full episodes (left) versus progressive training approach (right). To assess and compare the performance of different execution strategies, we establish a naive rule-based benchmark strategy and apply both reinforcement learning and PDE-based methods. The rule-based benchmark follows a simple inventory control rule: it trades at a constant speed of 100 lots per day whenever the inventory level (in absolute value) exceeds a predefined threshold of 5 lots, and does not trade otherwise. The RL-based approach aims to learn an optimal adaptive execution strategy by interacting with the market environment, dynamically adjusting its trading behavior based on real-time observations. Meanwhile, the PDE-based approach formulates the optimal execution problem using the Hamilton-Jacobi-Bellman equation presented in Eq. ( 7 ), deriving an optimal control strategy through numerical methods. For our numerical experiments, we consider three cases: two special cases where either \psi or \eta is set to zero, and a general case where both parameters are nonzero. 4.3.2 Case 1: \psi=0 For the case where \psi=0 , corresponding to purely quadratic execution costs ( L(v)=\eta v^{2} ), the HJB equation admits a closed-form solution, and the corresponding optimal control is given in Eq. ( 11 ). This solution describes an optimal policy that is linearly dependent on inventory, with a slope that evolves as a function of the remaining time until time T . As time approaches T , the absolute value of the slope increases rapidly, indicating that the optimal strategy is to gradually unwind the inventory early on and accelerate execution as the end of the trading period nears. Figure 3: Comparison of PDE-based optimal control (left) and RL-derived optimal policy (right) (solid lines) against the closed-form solution (dashed lines) at different time steps. Figure 3 compares the optimal policy obtained via the PDE numerical solution (on the left panel) and RL (on the right panel) against this theoretical benchmark. We see that both the RL-based and the PDE-based policies align well with the theoretical solution. However, for situations corresponding to large inventories, the approximations are not perfect. This is because these states are visited less frequently in the learning process in the case of RL, especially at the end of the training when the model has learned to avoid holding large inventories near time T . In the case of the PDE-based approach, this is due to the Neumann conditions at the boundaries. Figure 4 compares the total rewards achieved by the different strategies (the strategy associated with the theoretical solution is labeled as Closed-form in the figure). We clearly see that the naive rule-based benchmark is outperformed by both the RL and PDE-based solutions, which exhibit performance very close to the optimal closed-form solution. Figure 4: Histograms and density curves of total rewards obtained from 10,000 out-of-sample simulated episodes for the case \psi=0 . The density curves are estimated using Kernel Density Estimation (KDE) with a Gaussian kernel. The PDE-based solution produces a density curve that is very similar to the closed-form solution, making them nearly indistinguishable in the plot. 4.3.3 Case 2: \eta=0 In the case when \eta=0 , where execution costs are purely linear ( L(v)=\frac{\psi}{2}|v| ), there is no closed-form solution, so we rely on a comparison between the RL policy and the policy derived from the numerical solution of the HJB equation. Figure 5 shows the policies corresponding to the two numerical methods. Figure 5: RL-based and PDE-based policies for different times. Shaded regions indicate no-trading zones as identified by each strategy. A key observation in this case is the structure of the optimal control, which can be divided into two distinct zones. There exists an interval where it is optimal to remain inactive, executing no trade (full internalisation), while outside of this interval externalisation is optimal. Additionally, as the terminal time approaches, the no-execution zone shrinks to avoid terminal inventory penalties. For the PDE-based strategy, externalisation consists in trading a quantity that sends the inventory back to the frontier of the pure-internalisation interval. The reinforcement learning agent successfully captures the policy structure, with no execution within a given interval and an execution speed that increases with inventory outside of this interval. However, the frontier between internalisation and externalisation varies more over time and the RL agent does not bring the inventory back to the frontier in one step but adopts a less aggressive approach. Figure 6 compares the performance of the different strategies in an out-of-sample simulated environment. Both the HJB numerical solution and the RL policy significantly outperform the rule-based benchmark. On average, the PDE-based solution achieves a slight but consistent outperformance compared to the RL-based policy. However, this difference may be due to local maxima or flat regions in the objective function, resulting in multiple near-optimal solutions with similar value estimates. The latter may also explain the notable difference between the learned RL policy and the policy resulting from the numerical scheme, presented in Figure 5 . Figure 6: Histograms and density curves of total rewards obtained from 10,000 out-of-sample simulated episodes for the case \eta=0 . The density curves are estimated using KDE with a Gaussian kernel. 4.3.4 Case 3: \psi>0 and \eta>0 We now consider the case where the execution costs are composed of both linear and quadratic terms, i.e. L(v)=\frac{\psi}{2}|v|+\eta v^{2} . Figure 7 compares the RL-based and PDE-based policies for different times and inventories. Because \psi>0 , the PDE-based solution exhibits intervals where the control is 0 (internalisation) when the inventory is small (in absolute value), and the pure-internalisation interval gets smaller as we approach the terminal time. The RL-based policy exhibits similar characteristics but appears to be less aggressive for larger inventory values as in the pure quadratic case. Figure 7: RL-based and PDE-based policies for different times. Shaded regions indicate no-trading zones as identified by each strategy. Performance-wise, both approaches significantly outperform the naive benchmark policy, as illustrated in Figure 8 . The RL-based policy achieves an average accumulated reward within 0.5% of the PDE-base one. 6 6 6 The hypothesis of equal means is not rejected based on a two-sample t-test ( p -value = 0.07). Similarly, the Mann-Whitney U test does not reject the hypothesis that both distributions are identical ( p -value = 0.87). Both tests use a significance threshold of 5%. While the RL-based policy leads to slightly higher variance, it successfully learns a near-optimal control strategy. Figure 8: Histograms and density curves of total rewards obtained from 10,000 out-of-sample simulated episodes for the general case. The density curves are estimated using KDE with a Gaussian kernel. 5 Conclusion In this paper we studied the problem of optimally managing a stochastic order flow, taking into account market impact and execution costs as in models à la Almgren-Chriss. We proposed the use of an RL-based approach as an alternative to a more classical PDE-based approach in order to determine optimal trading policies. According to our results, our RL method converges to near-optimal solutions successfully, resulting in performance almost similar to the PDE-based solution, or exact solutions in contexts where they are known. A major benefit of RL is that no boundary conditions are needed, unlike with PDEs. As RL generalizes well to higher-dimensional problems where traditional PDE solvers suffer from the curse of dimensionality and can handle more complex market dynamics, it constitutes a promising approach for solving real-world execution problems. Context and Acknowledgements This paper is partly based on previous unpublished research conducted by Philippe Bergault and Olivier Guéant, supported by the Research Initiative “Nouveaux traitements pour les données lacunaires issues des activités de crédit,” financed by BNP Paribas under the aegis of the Europlace Institute of Finance. Hamza Bodor benefited from a “Bourse CIFRE” financed by BNP Paribas and contributed to reviving the topic with his expertise in reinforcement learning. The authors would like to express their gratitude for the continuous support provided by BNP Paribas. Nonetheless, the content of this article does not, in any manner, reflect the practices or policies of BNP Paribas.